I have setup 2 tabs using TabHost, both tabs have a listview. I have setup each listview so that when I click an item an action is completed which is working, the problem I am having is I am having to reload the app for the update to be shown on tab2, what I am wanting is when I open a tab the layout is refreshed for the tab on each open. To get the layout I am including it in my tabs XML.
My adapter has been setup and was working great when in MainActivity, the issue is only occurring since adding TabHost.
// My contentMain
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/Onglet1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/layouttab1" />
</LinearLayout>
// My adapter
ArrayAdapter<Store1> adapter = new MyTitleAdapter();
ListView myList = (ListView) findViewById(R.id.ListView);
adapterTitle.notifyDataSetChanged();
myList.setAdapter(adapter);
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("First Tab");
host.addTab(spec);
TabHost host = (TabHost)findViewById(R.id.tabHost);
host.setup();
spec = host.newTabSpec("Tab Two");
spec.setContent(R.id.tab2);
spec.setIndicator("Secong Tab");
//host.setOnTabChangedListener();
host.addTab(spec);
when you add item in listview, call one method (make it by own) in your adapter
public void refreshWishlistAdapter() {
itemList.clear();
itemList.addAll(dbHelper.getallWishlistItems());
itemsAdapter.notifyDataSetChanged();
}
use this method in fragment, so when you switch fragment this method executes:
private boolean isShown = false;
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (getView() != null) {
isShown = true;
// fetchdata() show data when page is selected
fetchData();
} else {
isShown = false;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.