마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

OnItemLongClickListener (리스트뷰 오래누르고있을때 리스너) 도와주세요.ㅠ

0 추천
  ArrayAdapter<String> adapter =  new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,item);
    listView.setAdapter(adapter);
 
로 리스트뷰에 DB에 list 테이블 중 제목만 쫙 뿌려주는걸 했습니다.
 
잘나왔는데요,
 
이제 오래누르고있으면 삭제를 하고싶은데,
 
 listView.setOnItemLongClickListener(new OnItemLongClickListener(){
 
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO 자동 생성된 메소드 스텁
//SQL  삭제
 
??
String del_name=?
db=help.getWritableDatabase();
String str="delete from list where name='"+del_name+"';";
//db.execSQL(str);
help.close();
return false;
}
    });
         
 
}
 
   
 
저 ?? 부분엔, 리스트뷰에서 어느 부분을 오래누루고있었으니까,
오래누룬부분에 있는 글씨가 del_name으로 가야되는데..
 
도무지 오래누룬곳의 스트링값을 빼오는법을 모르곘습니다.
 
도와주세요.ㅠㅠㅠ
 
 
 
윈엘 (160 포인트) 님이 2013년 7월 19일 질문

1개의 답변

0 추천

http://developer.android.com/intl/ko/reference/android/widget/AdapterView.OnItemLongClickListener.html

public abstract boolean onItemLongClick (AdapterView<?> parent, View view, int position, long id)

Added in API level 1

Callback method to be invoked when an item in this view has been clicked and held. Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.

Parameters
parent The AbsListView where the click happened
view The view within the AbsListView that was clicked
position The position of the view in the list
id The row id of the item that was clicked
Returns
  • true if the callback consumed the long click, false otherwise

 

두 번째 인자로 선택한 position 값이 들어 옵니다. 님의 경우 arg2 겠죠

Strnig del_name = item[arg2];

 

aucd29 (218,390 포인트) 님이 2013년 7월 22일 답변
...