Tabhost with two listviews with Custom array Adapter, both list showing same data
I have one activity in which I am having one TabHost with two tabs. Both the tabs have one listview each. The activity has one button which start an aync job to get data from internet and then the data is divided into two array adapters one for each listview. Here comes the problem, both the listview are showing the data from the second adapter.
ArrayList<TestClass> detailsToCollect = new ArrayList<TestClass>();
ArrayList<TestClass> detailsToGi开发者_JAVA百科ve = 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);
}
Can anybody tell me what is the problem here? Thanks, Ashwani
I have a similar problem: Tab Host List Adapter and Lists, that i didn't fix totally yet but one idea is that my layout got better after I put a non transparent background (an image) for each one of the lists. Before I used to see the 4 lists on top of each other but now I see only one so maybe your problem can also be fixed that way.
I have fixed the issue by handling setOnTabChangedListener for the tabhost. In this listener I am binding the listviews again to their corresponding adapters.
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;
}
}
精彩评论