Refresh Listview When Using Hashmap
Solution 1:
This is probably because findFragmentByTag() is not able to find the required fragment and so is returning null, resulting in NullPointerException when you try to access it. You can try a workaround by retrieving the tag for fragment and storing it in activity class variable for further access as follows:
In your activity class, declare a private String variable and getter/setter methods for it:
publicString fragmentView1Tag;
publicStringgetfragmentView1Tag() {
return fragmentView1Tag;
}
publicvoidsetfragmentView1Tag(String fragmentView1Tag) {
this.fragmentView1Tag = fragmentView1Tag;
}
In FragmentView1 class, retrieve the tag of the fragment and set fragmentView1Tag variable:
Stringtag= getTag();
((YourActivityName) getActivity()).setfragmentView1Tag(tag);
And now while retrieving the fragment in activity class, use the above getter method:
FragmentView1f= (FragmentView1) this.getSupportFragmentManager().findFragmentByTag(getfragmentView1Tag);
Solution 2:
Use a cursor to get all the rows from the database. Then use a cursor adapter to populate the list. After you add a new row to the database, just call notifyDataSetChanged(); on the cursor adapter.
Post a Comment for "Refresh Listview When Using Hashmap"