从ListFragment中删除Indefinite ProgressDialog

时间:2012-11-28 14:20:09

标签: android android-activity fragment progressdialog android-fragmentactivity

我有一个从SQLite数据库加载东西的ListFragment,并且有一个不想消失的循环loadingdialog。使用setListShown(true);setListShownNoAnimation(true);尝试无济于事。我不希望任何加载栏/屏幕/对话框留在屏幕上。

enter image description here

My FragmentActivity:

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();

    }

我的ListFragment:

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" />

2 个答案:

答案 0 :(得分: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"是罪魁祸首。

答案 1 :(得分:0)

我解决了。我不得不在XML中手动设置我的片段类到我的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"/>