0

I have Tabs with 3 fragments and in first tab I have registration form that save data to sqlite in second tab I have list that pull data from that database and shows it in simple listview, so How can make that when save button clicked in first tab, second tab list view should automatically updated without restarting activity

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);
Sasha
  • 644
  • 8
  • 22

1 Answers1

1

check this solution. I think it will for you too. 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);
}
Community
  • 1
  • 1