javaandroidandroid-listviewlistactivity

Use LongClickListener in ListActivity


protected void onListItemClick (ListView l, View v, int position, long id)

The normal method works fine for me but is there also a method for a long click? Since I am on a ListActivity I cant use:

listview.setOnItemLongClickListener(new OnItemLongClickListener() 

because i cant initialize listView bc of ListActivity.


Solution

  • OK I found a nice solution for it:

    ListView lv = getListView();
        lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int row, long arg3) {
    
                 System.out.println("REIHE "+row);
                 return true;
    
            }
        });