Reputation: 305
I'm trying to get selected items from main list, and updating them to other sub list, but when i click on main list item, all items of list will become invisible except the one i select, and only that element is updating to sub list, what might be the problem?... below code snippet shows what i'm doing....
ListView list,selectedList;
LazyAdapter adapter, adapter1;
String mStrings[]={"item1","item2","item3","item4","item5","item6","item7"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list=(ListView)findViewById(R.id.list);
adapter=new LazyAdapter(this, mStrings);
list.setAdapter(adapter);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(listener);
list.setOnItemClickListener(new OnItemClickListener(){
ArrayList<String> years = new ArrayList<String>();
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
SparseBooleanArray checked = list.getCheckedItemPositions();
if(checked.get(arg2))
{
years.add(mStrings[arg2]);
}
else
{
years.remove(mStrings[arg2]);
}
if(years.size()!=0)
{
String selectedItems[]=new String[years.size()];
for(int i=0;i<years.size();i++)
selectedItems[i]=years.get(i);
selectedList=(ListView)findViewById(R.id.selectedList);
adapter1=new LazyAdapter(MainActivity.this, selectedItems);
selectedList.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
}
}});
}
Upvotes: 1
Views: 229
Reputation: 38168
It would be better to use the same instance of adapter and change its content, then notify of data changes (as you do).
Recycle your adapter instead of creating a new one.
Upvotes: 1