0

나는 목록이 컨텍스트 메뉴에 등록되어있는 SimpleCursorAdapter를 사용하여 목록보기를 만드는거야 ... 다음은 업데이트 목록 항목은

registerForContextMenu(listView); 

이 내 전체 목록을 업데이트 onContextItemSelection

@Override 
public boolean onContextItemSelected(MenuItem item) { 

switch (menuItemIndex) { 
    case 0:{ 
     //perform some action 
       //then update the adapter 
       Cursor newCursor = fetchNewCursor(); 
     if(newCursor .moveToFirst()){ 
      adapter.swapCursor(newCursor); 
      adapter.notifyDataSetChanged(); 
       }//if ends    
     }// case 0 ends    
     break; 
}//switch ends 
}//onContextItemSelected() ends 

입니다 onContextItemSelected 보기, 특정 목록 항목 만 (길게) 클릭 만 업데이트하려는 다른 context menu 항목을 추가하고 싶습니다. 내가 그렇게 할 수있는 방법 ...

이 내 Cursor Adapter

@Override 
    public View newView (Context context, Cursor cursor, ViewGroup parent) { 
      return viewInflater.inflate(layout, null); 
    } 

같은 외모와 bindView 방법

@Override 
    public void bindView(View view, Context context, Cursor cursor) { 
     super.bindView(view, context, cursor); 

     TextView t1=(TextView)view.findViewById(R.id.txt_one); 
     TextView t2=(TextView)view.findViewById(R.id.txt_two); 

     t1.setText(cursor.getString(...)); 
     t2.getString(cursor.getString(...)); 
} 

관련

답변

1

당신은에서 선택한 항목의 인덱스를 얻을 수있는 방법이다 전화 걸기 목록

lv.getSelectedItemPosition(); 

그리고 그 위치에 목록 항목에서 항목을 업데이트하고 어댑터 통지 :

@Override 
public boolean onContextItemSelected(MenuItem item) { 

switch (menuItemIndex) { 
    case 0:{ 
     //perform some action 
       //then update the adapter 
       Cursor newCursor = fetchNewCursor(); 
     if(newCursor .moveToFirst()){ 
      adapter.swapCursor(newCursor); 
      adapter.notifyDataSetChanged(); 
       }//if ends    
     }// case 0 ends    
     break; 
    case 1: 
     <ItemType> item=lv.getSelectedItem(); 
     <UPdateItem> 
     adapter.notifyDataSetChanged(); 
     break; 
}//switch ends 
}//onContextItemSelected() ends 
+0

어떤'lv.getSelectedItem(); '반환을? – dakait

+0

어댑터에서 ArrayAdapter 을 설정하면 getSeletedItem이 선택한 인덱스에서 항목을 반환합니다. –

+0

메신저 ArrayAdapter를 사용하고 있지 않습니다. 어댑터가'public class MyListAdapter extends SimpleCursorAdapter {'아이템을 얻은 후 어떻게 보이나요? 텍스트 뷰를 어떻게 얻을 수 있습니까? – dakait