hi all,
can any one show me a simple example how can I create ListView using code, not xml...
and add item into list and remove item in the list anyway I wan???
wesley.


gecu_121 wrote:hello,
use the following code to get your work done...Using java Syntax Highlighting
package com.pack.listactivity; import android.app.ListActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyList extends ListActivity{ private String[] itemNames = {"Item1", "Item2", "Item3", "Item4", "Item5"}; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, itemNames)); getListView().setTextFilterEnabled(true); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onListItemClick(l, v, position, id); Log.v("Done", "Item clicked is " + position); } }Parsed in 0.034 seconds, using GeSHi 1.0.8.4
in onListItemClick, you can do what you wanted.

Users browsing this forum: Google Feedfetcher and 3 guests