Shweta
Shweta

Reputation: 1145

How to set onItemClickListener using SimpleCursorAdapter using android.R.id.list

Hi I am trying to implement OnItemClickListener using android.R.id.list which is inbuild list in android using ListActivity. Is there any other way so that i can use onItemclickLietener without placing ListView object in front of OnItemClickListener. Please suggest.

Also I wan to set delete and update method using longclick listener using Database "update and delete " methods. So please help me out.

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.file_row, c, from, to);
setListAdapter(adapter);
getnotelist.close();

WhatToPutHere?.setOnItemClickListener(new OnItemClickListener()
{
    @Override public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3)
    { 
        Toast.makeText(SuggestionActivity.this, "" + position, Toast.LENGTH_SHORT).show();
    }
}); 

How to use this using android.R.id.list or How to get ListView in ListActivity

Upvotes: 1

Views: 1794

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

if you are extending ListActivity then add setOnItemClickListener as:

getListView().setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent,
                                      View view,int position, long id) {

               // do your work here
        }
      }); 

You can get ListView as if extending ListActivity:

ListView listview = getListView(); 

or by using android.R.id.list as

ListView listview = (ListView)findViewById(android.R.id.list);

Upvotes: 4

Related Questions