[英]Implementation of two listviews in one frame
i'm working on two listviews in a same activity in which there are 3 strings in 1st one and the 2nd listview is blank . 我正在同一活动中的两个列表视图上工作,其中在第一个列表中有3个字符串,而第二个列表视图为空白。 i want to trasfer the values of first list into second list, whenever any value is pressed. 每当按下任何值时,我都希望将第一列表的值转移到第二列表中。
listView1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView1
.getItemAtPosition(position);
secoundList.add(itemValue);
firstList.remove(position);
Toast.makeText(
getApplicationContext(),
"Position :" + itemPosition + " ListItem : "
+ itemValue, Toast.LENGTH_SHORT).show();
}
});
But everytime i get error in logcat that "the content of adapter has changed but listview didnot recieve any notification " The error of the log cat that "make sure the content of adapter is not modified from a background thread" 但是每次我在logcat中收到错误消息时,“适配器的内容已更改,但listview没有收到任何通知”日志猫的错误,“确保未从后台线程修改适配器的内容”
您必须在修改列表后调用此方法。
listAdapter.notifyDataSetChanged();
If I understand your question right, then you r trying to selected listitem from one list you want to show that selected list item in second list view.? 如果我对您的问题理解正确,那么您尝试从一个列表中选择列表项,然后在第二个列表视图中显示该列表项。
I will give You question according to what i understand. 我会根据我的理解向您提问。
so first of all you need to initilize the first list with item. 所以首先您需要初始化第一个带有item的列表。
ListView listview1 = findViewBId(---------);
ListView listview2 = findViewBId(---------);
ArrayList<String> list1 = new ArrayList<String>();
list1.add("abc");
list1.add("pqr");
list1.add("pqr");
--------------------
ArrayList<String> list2 = new ArrayList<String>();
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(context, resource, list1 );
listView1.setAdapter(adapter1 );
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(context, resource, list2 );
listView1.setAdapter(adapter2 );
listView1.setOnItemClickListener(this);
onItemClick(AdapterView<?> parent, View view, int position, long id) {
list2.add(list1.get(position));
adapter2.notifyDataSetChanged();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.