【问题标题】:How to refresh listview from another fagment tab如何从另一个片段选项卡刷新列表视图
【发布时间】:2016-03-01 15:08:48
【问题描述】:

我有带有 3 个片段的选项卡,在第一个选项卡中我有注册表单,可以将数据保存到第二个选项卡中的 sqlite 我有从该数据库中提取数据并在简单列表视图中显示的列表,所以当点击保存按钮时如何做到这一点在第一个选项卡中,第二个选项卡列表视图应自动更新而无需重新启动活动

View v = inflater.inflate(R.layout.tab_2,container,false);
        mListView = (ListView) v.findViewById(R.id.lvMain);
        DataBaseHandler db = new DataBaseHandler(getActivity());

        List<Contact> contacts = db.getAllContacts();
        List<String> your_array_list = new ArrayList<String>();

        for (Contact cn : contacts) {
            String log = "ID:" + cn.get_id() + " Name: " + cn.get_name()
                    + cn.get_cena()+" "+cn.getJob()+" "+cn.get_opis();
            your_array_list.add(cn.get_name());
            // Writing Contacts to log
            Log.d("77777777777777: ", log);
            //add contacts data in arrayList
            //imageArry.add(cn);

        }

       // your_array_list.add("bar");
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                getActivity(),
                android.R.layout.simple_list_item_1,
                your_array_list );
        mListView.setAdapter(arrayAdapter);

【问题讨论】:

    标签: android listview tabs


    【解决方案1】:

    检查此解决方案。我想它也适合你。 How do I update ListView in another Fragment?

    @Override
    public void onPageSelected(int position) {
    ListViewFragment frag=(ListViewFragment)adapter.instantiateItem(viewPager, 1);
    //here adapter is the ViewPager Adapter and you must supply the viewpager that    contains 
    //the fragments and also the position of the fragment to instantiate. 
    //For example 0 or 1 etc.
    frag.populateListView(getApplicationContext());
    aBar.setSelectedNavigationItem(position);
    }
    

    【讨论】:

    • 我应该把这个放在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-26
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多