0
이 문제에 대한 모든 게시물을 읽었지만 여전히 ListView를 업데이트 할 수 없습니다. ListActivity가 확장되었습니다. 내가 파일을 삭제할 때리스트 뷰 업데이트 할 지금notifyDataSetChanged가 업데이트되지 않음 ListView
public List<String> songs = new ArrayList<String>();
public ArrayAdapter<String> allsongs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
allsongs = new ArrayAdapter<String>(this,
R.layout.song_items, songs);
BindAllSongs();
ListView listView=getListView();
registerForContextMenu(listView);
}
: 여기 내 ArrayAdapter와의 내 BindAllSongs에서
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.delete_file:
File file = new File(Environment.getExternalStorageDirectory().getPath() + "/AudioStreamRecorder/" + getListView().getAdapter().getItem(info.position).toString());
file.delete();
runOnUiThread(new Runnable() {
public void run() {
allsongs.notifyDataSetChanged();
}
});
return true;
case R.id.cancel:
return true;
default:
return super.onContextItemSelected(item);
}
}
(); 방법 :
public void BindAllSongs() {
...
...
setListAdapter(allsongs);
}
이 방법은 훌륭합니다 (파일은 SD 카드에서 삭제됨). 그러나 목록은 업데이트되지 않습니다. 이동 한 다음 ListView로 돌아 가면 항목이 사라집니다. (ListView로 돌아 오면 BindAllSongs();이 호출됩니다. 더 많은 정보가 필요하시면 언제든지 알려주십시오.
감사합니다. 그러나 어떻게해야할지 모르겠습니다. –
당신은'((ArrayAdapter) getListAdapter()). remove (item)'를 호출한다. 당신은'getListAdapter(). getItem (position)'으로 아이템을 얻을 수있다. 어댑터의 remove 메소드를 대체하고 해당 메소드를 사용하여 파일을 삭제하고 목록에서 항목을 제거 할 수도 있습니다. – toadzky
감사합니다! 나는 다시보고하려고 노력할 것이다. –