When creating a class, I specified an OnItemClickListener interface. The elements of the list themselves are the layout specified in the xml markup. When I used the built-in simple_list_item_1 , everything worked.

Notes here is a separate class, HashMap . Its objects store data for one item.

 public class MainActivity extends ListActivity implements AdapterView.OnItemLongClickListener { private DatabaseManager mDatabaseManager; private SQLiteDatabase dbHelp; public void add() { Intent newNote = new Intent(this,addNote.class); startActivity(newNote); } private void outputNotes() { mDatabaseManager = new DatabaseManager(this); dbHelp = mDatabaseManager.getWritableDatabase(); Cursor cursor = dbHelp.query(mDatabaseManager.DB_TABLE,new String[]{mDatabaseManager.NOTES_HEADER_COLUMN, mDatabaseManager.NOTES_NOTE_COLUMN},null,null,null,null,null); cursor.moveToFirst(); String headerNote, bodyNote; ArrayList<Notes> NotesList = new ArrayList<Notes>(); LinearLayout container = (LinearLayout)findViewById(R.id.container); while(cursor.isAfterLast()==false) { headerNote = cursor.getString(cursor.getColumnIndex(mDatabaseManager.NOTES_HEADER_COLUMN)); bodyNote = cursor.getString(cursor.getColumnIndex(mDatabaseManager.NOTES_NOTE_COLUMN)); NotesList.add(new Notes(headerNote,bodyNote)); cursor.moveToNext(); } ListAdapter adapter = new SimpleAdapter(this,NotesList,R.layout.view_notes, new String[]{Notes.HEADER, Notes.BODY}, new int[]{R.id.header_of_note,R.id.body_of_note}); setListAdapter(adapter); cursor.close(); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); outputNotes(); } @Override protected void onResume() { super.onResume(); outputNotes(); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Toast.makeText(getApplicationContext(),"Работает",Toast.LENGTH_SHORT).show(); } @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(),"Длинное нажатие",Toast.LENGTH_SHORT).show(); return true; } } 
  • It seems that the methods are not those ... There must be something like protected void onItemClickListener and ...onItemLongClickListener , it seems. I also do not see who exactly you are using these methods. Probably wrong, did not work with this - whalemare
  • And now only long press works? - Shwarz Andrei

0