我有一个从 SQLite 数据库加载内容的 ListFragment,并且有一个不想消失的循环加载对话框。尝试使用setListShown(true);
但setListShownNoAnimation(true);
无济于事。我不希望任何加载栏/屏幕/对话框留在屏幕上。
我的片段活动:
public class ListOverviewActivity extends FragmentActivity {
DatabaseManager db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_overview);
}
@Override
public void onStart() {
super.onStart();
//db = new DatabaseManager(getApplicationContext());
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment payListFragment = new PayListFragment();
fragmentTransaction.replace(R.id.paylist_fragment, new PayListFragment());
fragmentTransaction.show(payListFragment);
fragmentTransaction.commit();
}
我的列表片段:
public class PayListFragment extends ListFragment {
DatabaseManager db;
ArrayList<PayList> lists;
PayListAdapter pAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public PayListFragment() {
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
db = new DatabaseManager(getActivity());
lists = db.getAllLists();
pAdapter = new PayListAdapter(getActivity(), lists);
setListAdapter(pAdapter);
registerForContextMenu(getListView());
setListShown(true);
setListShownNoAnimation(true);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
// int group = (int) ExpandableListView.getPackedPositionForGroup((int) info.position);
// int type = ExpandableListView.getPackedPositionType((int) info.position);
// int child = ExpandableListView.getPackedPositionChild((int) info.position);
menu.setHeaderTitle(lists.get(info.position).getTitle());
menu.add(0, 0, 0, "Delete");
}
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case 0:
Toast.makeText(getActivity(), "DEBUG: Deleting", Toast.LENGTH_SHORT).show();
db.deleteList(lists.get(info.position));
pAdapter.notifyDataSetChanged();
setListAdapter(pAdapter);
return true;
}
return false;
}
}
和我的一段xml:
<fragment
android:id="@+id/paylist_fragment"
android:name="android.support.v4.app.ListFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_below="@+id/relativeLayout2"
android:visibility="gone"
tools:layout="@layout/listview_list" />