ListView and onLongPress

Put your problem here if it does not fit any of the other categories.

ListView and onLongPress

Postby Malefico » Thu Nov 20, 2008 10:03 am

I would like to implement the onLongPoress listener on a ListView.. its easy.. but i don't know how to determine wich item i click..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. protected void applyViewLongPressListener() {
  3.  
  4.     final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener(){
  5.  
  6.          @Override
  7.  
  8.          public void onLongPress(MotionEvent e) {
  9.  
  10.               // handle longpress to ListView...
  11.  
  12.                 long id =mList.getSelectedItemPosition();
  13.  
  14.                 Toast.makeText(CustomersSearch.this,"ID=" + id,Toast.LENGTH_SHORT).show();
  15.  
  16.         }              
  17.  
  18.     });
  19.  
  20.    
  21.  
  22.  
  23.  
  24.     CustomersSearch.this.mList.setOnTouchListener(new OnTouchListener(){
  25.  
  26.         @Override
  27.  
  28.         public boolean onTouch(View v, MotionEvent ev) {
  29.  
  30.             return gd.onTouchEvent(ev);
  31.  
  32.         }
  33.  
  34.    });
  35.  
  36.    
  37.  
  38. }      
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


But the id is always -1: there isnt item selected..
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Top

Postby Malefico » Thu Nov 20, 2008 5:12 pm

:roll:
Malefico
Developer
Developer
 
Posts: 30
Joined: Fri Oct 24, 2008 3:32 pm

Postby MrSnowflake » Thu Nov 20, 2008 6:02 pm

[s]Uhm, why don't u use the setOnLongClickListener() in View?[/s]

I searched the Google and found this tutorial.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests