2015-01-03 2 views
0
@Override 
    protected void onListItemClick(final ListView l, final View v, 
      final int position, final long id) { 

     super.onListItemClick(l, v, position, id); 


     final FriendInfo friend = friendAdapter.getItem(position); 
     String selection = l.getItemAtPosition(position).toString(); 

} 

답변

0

어댑터에서 항목을 제거해야합니다. 그렇게하는 방법은 friendAdapter의 어댑터 유형에 따라 다릅니다. 이 ArrayAdapter와의 경우 예를 들어, 정말 쉽게 : friendAdapter 다음 어떻게 든 당신은 기본 데이터에서 friend 항목을 제거해야 어댑터의 다른 유형

@Override 
protected void onListItemClick(final ListView l, final View v, final int position, final long id) { 
    super.onListItemClick(l, v, position, id); 

    final FriendInfo friend = friendAdapter.getItem(position); 
    String selection = friend.toString(); 
    // do something with selection 

    friendAdapter.remove(friend); 
    friendAdapter.notifyDataSetChanged(); 
} 

합니다. 항목을 제거한 후 어댑터가 변경되었음을 목록에 알려야합니다. ArrayAdapter의 경우, 이는 notifyDataSetChanged을 호출하는 것을 의미하지만 일부 다른 어댑터의 경우 새 어댑터를 구성하고 setAdapter을 다시 호출하는 것을 의미 할 수 있습니다.

잘 모르는 경우, 어댑터 구성 유형을 포함하여 어댑터를 구성하는 코드를 보여주십시오. 그 코드를 통해 도움을받을 수 있습니다.

관련 문제