1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
   | public class MainActivity extends Activity {
	private Object TestAsyncTask;
	private ListAdapter htlAdapt = null;
	private ListView htlListView = null;
	private String title;
 
	private ItemStructure reservationdata = new ItemStructure();
	static ArrayList<ItemStructure> Content = new ArrayList<ItemStructure>();
 
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// setContentView(R.layout.main);
		setContentView(R.layout.activity_main);
		// TextView hotelname=(TextView)findViewById(R.id.slist);
		htlListView = (ListView) findViewById(R.id.list);
		htlAdapt = new ListAdapter(this, R.layout.item_activity, Content);
		htlListView.setAdapter(htlAdapt);
		getURL("http://www.aaa.com/arr.xml");
		((ListView)findViewById(R.id.list)).setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView arg0, View v, int position, long id) {
			// Nous d�finissons notre intent en lui disant quelle classe il faut utiliser
			Intent detail_article= new Intent(getApplicationContext(),autre_activite.class);
			// On lui transmet des param�tres, ici la position de l'entry du  feed que l'on voudra ouvrir
			// On peut passer tous les types primitifs (long, int , boolean)
			detail_article.putExtra("title", position);
 
			// On d�marre l'activity
			startActivity(autre_activite);
			// On ferme l'activity en cours
			}
			});
 
 
	}
 
 
 
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
 
 
	}
 
 
 
	public void getURL(String url) {
		TestAsyncTask test = new TestAsyncTask();
 
		test.setContext(this);
 
		test.execute(url);
	}
 
	class TestAsyncTask extends
			AsyncTask<String, Void, ArrayList<ItemStructure>> {
 
		// private String Content;
 
		ArrayList<ItemStructure> Contents = null;
		private String Error = null;
		private ProgressDialog Dialog;
		private Context ctx;
 
		public void setContext(Context ctx) {
			this.ctx = ctx;
		}
 
		protected void onPreExecute() {
			Dialog = new ProgressDialog(ctx);
			Dialog.setMessage("Loading Data...");
 
			Dialog.show();
		}
 
		protected ArrayList<ItemStructure> doInBackground(String... urls) {
 
			try {
 
				Log.i("INFOOOOOO", "++++++++1");
				Contents = URLHelper.executeRequest();
 
				Log.i("INFOOOOOO", "++++++++" + Contents.size());
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
 
			return Contents;
		}
 
		protected void onPostExecute(ArrayList<ItemStructure> content) {
 
 
			if (Error != null) {
				Toast.makeText(ctx, "Pls Try Again  " + Error,
						Toast.LENGTH_LONG).show();
			} else {
				updateView(content);
 
			}
			Dialog.dismiss();
		}
	}
 
	private void updateView(ArrayList<ItemStructure> content) {
 
		this.Content.clear();
 
		this.Content.addAll(content);
 
		this.htlAdapt.notifyDataSetChanged();
	}
	public String getTitle1() {
		return title;
	}
 
	public void setTitle1(String title) {
		this.title = title;
	}
 
} | 
Partager