Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't update a ListView inside a TabHost's FrameLayout
    primarykey
    data
    text
    <p>I have a TabActivity with a single ListView inside TabHost's FrameLayout. This ListView is shared among my 3 tabs. The items of the list are downloaded from the internet using a Handler, but the list is not being updated when the data come. When I select another tab, the list updates itself, but I want to be able to see it being updated after download. I've already tried to invalidate the ListView, the FrameLayout and the TabHost, but nothing happens. The notifyDataSetChanged() and notifyDataSetInvalidated() methods don't help either. If I put the ListView out of the FrameLayout, it works as expected. Here's the code:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; </code></pre> <p></p> <pre><code>&lt;TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/comments_list_lv" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/FrameLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p> </p> <pre><code> public class CommentsActivity extends TabActivity implements Handler.Callback, OnTabChangeListener { private static final int take = 20; private Handler handler; private CommentsListModel model = null; private ListView listView; private CommentsListAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.comments_activity); handler = new Handler(this); setContentView(R.layout.comments_activity); listView = (ListView) findViewById(R.id.comments_list_lv); listView.setTextFilterEnabled(true); getTabHost().setOnTabChangedListener(this); buildTabs(); setListView(); requestData(); } @Override public boolean handleMessage(Message msg) { AbstractResponse response = (AbstractResponse) msg.obj; ResponseStatus status = response.getStatus(); if (status.getResponseCode() == ResponseStatus.OK) { model = (CommentsListModel) response.getResponseObject(); adapter = new CommentsListAdapter(this, model.getComments()); listView.setAdapter(adapter); } return true; } @Override public synchronized void onTabChanged(String tabName) { if (model != null) { Resources res = getResources(); CommentsFilter filter = null; if (tabName.equals(res.getString(R.string.comments_all))) { filter = new CommentsFilter(model.getComments(), CommentsFilter.ALL); } else if (tabName.equals(res.getString(R.string.comments_liked))) { filter = new CommentsFilter(model.getComments(), CommentsFilter.LIKED); } else if (tabName.equals(res.getString(R.string.comments_disliked))) { filter = new CommentsFilter(model.getComments(), CommentsFilter.DISLIKED); } adapter = new CommentsListAdapter(this, filter.filter()); listView.setAdapter(adapter); } } private void buildTabs() { Resources res = getResources(); TabHost tabHost = getTabHost(); String tabName = res.getString(R.string.comments_all); TabHost.TabSpec spec = tabHost.newTabSpec(tabName); spec.setIndicator(tabName, null); spec.setContent(R.id.comments_list_lv); tabHost.addTab(spec); tabName = res.getString(R.string.comments_liked); spec = tabHost.newTabSpec(tabName); spec.setIndicator(tabName, null); spec.setContent(R.id.comments_list_lv); tabHost.addTab(spec); tabName = res.getString(R.string.comments_disliked); spec = tabHost.newTabSpec(tabName); spec.setIndicator(tabName, null); spec.setContent(R.id.comments_list_lv); tabHost.addTab(spec); } private void requestData() { AbstractRequest request = new CommentsRequest(barcode, 0, take); request.addListener(handler); Message msg = new Message(); msg.what = ApplicationActions.ProtocolActions.REQUEST; msg.obj = request; msg.setTarget(AsyncRequestController.getInstance().getInboxHandler()); msg.sendToTarget(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload