我的片段中有以下代码,用于在列表视图中显示文件夹中的所有文件。我还添加了从列表视图中删除文件的功能。删除最后一个文件后,我想显示一个不同的 xml 布局,如果选项卡已更改,但如果列表视图中的最后一项被删除,则不是实时的。
mFrame3 = (RelativeLayout) inflater.inflate( R.layout.ptrip, container, false ); //display if file exist
noFilesDisplayed = (RelativeLayout) inflater.inflate(R.layout.nofile, container, false); //display if file doesn't exist
if (FilesInFolder != null) {
mFrame3.setVisibility(View.VISIBLE); //display the listview
noFilesDisplayed.setVisibility(View.GONE); //hide it
}
else {
mFrame3.setVisibility(View.GONE); //hide it
noFilesDisplayed.setVisibility(View.VISIBLE); //display if no file exist in the folder
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
int menuItemIndex = item.getItemId();
String[] menuItems = getResources().getStringArray(R.array.menuSelect);
String menuItemName = menuItems[menuItemIndex];
String txt = ((TextView) info.targetView.findViewById(R.id.txtTitle)).getText().toString();
if (menuItemIndex == 0) {
if (folder.exists()) {
//File flEachFile = new File(folder.toString() + "/" + currentFileName + ".tp");
flEachFile = new File(folder.toString() + "/" + txt + ".tp");
flEachFile2 = new File(folder.toString() + "/." + txt + ".tp");
if (flEachFile.exists()) {
flEachFile.delete();
}
if (flEachFile2.exists()) {
flEachFile2.delete();
}
adapter.remove(adapter.getItem(info.position));
adapter.notifyDataSetChanged();
dataList.setEmptyView(noFilesDisplayed);
//getActivity().getActionBar().setSelectedNavigationItem(1);
}
}
return true;
}
没有发生的是,一旦从列表视图中删除最后一项,以下命令不会更改视图:dataList.setEmptyView (noFilesDisplayed);
显示最后一个文件后如何实现视图更改?也许刷新选项卡视图本身?