0

我有一个从 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" />
4

2 回答 2

0

在您的布局中使用它:

<fragment
    android:id="@+id/paylist_fragment"
    android:name="com.your.app.PayListFragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/relativeLayout2"
    tools:layout="@layout/listview_list" />

我认为android:visibility="gone"是罪魁祸首。

于 2012-11-28T14:41:15.560 回答
0

我解决了。我不得不手动将 XML 中 Fragment 的 Class 设置为 PayListFragment 类,然后微调器消失了!

我现在的 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"
    class="com.name.billsplitter.PayListFragment"
    tools:layout="@layout/listview_list"/>
于 2012-11-29T09:06:14.960 回答