【问题标题】:Tabhost with two listviews with Custom array Adapter, both list showing same data带有自定义数组适配器的两个列表视图的 Tabhost,两个列表都显示相同的数据
【发布时间】:2011-05-19 15:59:32
【问题描述】:

我有一项活动,其中我有一个带有两个选项卡的 TabHost。两个选项卡各有一个列表视图。该活动有一个按钮,用于启动 aync 作业以从 Internet 获取数据,然后将数据分为两个数组适配器,每个数组适配器一个用于列表视图。问题来了,两个列表视图都显示来自第二个适配器的数据。

ArrayList<TestClass> detailsToCollect = new ArrayList<TestClass>();
ArrayList<TestClass> detailsToGive = new ArrayList<TestClass>();
for (TestClass TestClass : details) {
if(TestClass.getAmount()>0)
{
detailsToCollect.add(TestClass);
}
else
{
TestClass.setAmount(TestClass.getAmount()*-1);
detailsToGive.add(TestClass);
}
}
if(Double.parseDouble(amount)!=0)
{
imgView1.setVisibility(View.VISIBLE);
downloadFile(GetGraphURL(a, al),imgView1);
lstView1.setVisibility(View.VISIBLE);
lstView1.setAdapter(new CustomAdapter(Home.this,R.layout.detailsrow, detailsToCollect));
}
else
{
nodataCollect.setVisibility(View.VISIBLE);
}
if(Double.parseDouble(amountc)!=0)
{
imgView2.setVisibility(View.VISIBLE);
downloadFile(GetGraphURL(ac, alc),imgView2);
lstView2.setVisibility(View.VISIBLE);
lstView2.setAdapter(new CustomAdapter(Home.this,R.layout.detailsrow, detailsToGive));
}
else
{
nodataGive.setVisibility(View.VISIBLE);
}

谁能告诉我这里有什么问题? 谢谢, 阿什瓦尼

【问题讨论】:

  • 我在您发布的代码中看不到问题,您是否已将其修改为在此处发布?也许问题出在其他地方,也许为 detailsToGive 和 detailstoCollect 创建一个 getter 和 setter 方法,然后添加 Log.d() 以检查它们是否按预期被调用
  • 你好,我调试了代码,两个arraylists有不同的元素,但是绑定后两个listviews有相同的数据。

标签: android android-listview


【解决方案1】:

我有一个类似的问题:Tab Host List Adapter and Lists,我还没有完全解决,但一个想法是,在我为每个列表放置非透明背景(图像)后,我的布局变得更好。以前我看到 4 个列表相互重叠,但现在我只看到一个,所以也许你的问题也可以这样解决。

【讨论】:

  • 我已通过处理 setOnTabChangedListener 并在选项卡单击时设置适配器来解决此问题。
【解决方案2】:

我已通过处理 tabhost 的 setOnTabChangedListener 解决了这个问题。在这个监听器中,我将列表视图再次绑定到它们相应的适配器。

public void onTabChanged(String arg0) {

                    int type = arg0=="tab_1"?1:0;
                    switch (type) {

                    case 1: 
                         lstView1.setAdapter(ListView1Adapter);
                          break;

                    default:
                         lstView2.setAdapter(ListView2Adapter);
                         break;
                    }

                }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多