Question

I have the following code snippet.

public class ImageStoreActivity extends ListActivity {
private DBHelper mDB;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDB = new DBHelper(this);

    mDB.Reset();

    Bitmap img = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    mDB.createItemEntry(new ListObject(img, "x",   "999999", "blah"));
    mDB.createItemEntry(new ListObject(img, "y",     "56789", "blah blah"));
    mDB.createItemEntry(new ListObject(img, "Pfirsich", "4112344", "blaflakf"));
    mDB.createItemEntry(new ListObject(img, "Zitrone",  "4023232", "511131"));

    String[] columns = {mDB.KEY_ID, mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_PHONE, mDB.KEY_RELATION};
    String   table   = mDB.RELATION_TABLE;

    Cursor c = mDB.getHandle().query(table, columns, null, null, null, null, null);

    startManagingCursor(c);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.main,
            c,
            new String[] {mDB.KEY_IMG, mDB.KEY_NAME, mDB.KEY_PHONE, mDB.KEY_RELATION},
            new int[] {R.id.img, R.id.txt, R.id.textview,R.id.textview1});

    adapter.setViewBinder(new ItemViewBinder());
    setListAdapter(adapter);
  } 
}

how do i add this code

public void onItemClick(AdapterView parentView, View v,
                int position, long id) {} 

to the above code. please help me

Was it helpful?

Solution

add this code after setListAdapter(adapter);

final ListView lv = getListView();
lv.setTextFilterEnabled(true);  
lv.setOnItemClickListener(new OnItemClickListener() {
   public void onItemClick(AdapterView<?> parent, View view, int position, long id) {                    
    // add the array list here..    
    }        
}); 

OTHER TIPS

Override the onListItemClick() method, like this,

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
        // Do something here
        ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top