Android的ListView的滚动后丢失的数据 [英] Android listView lost the data after scroll
本文介绍了Android的ListView的滚动后丢失的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题,我的ListView!
当我改变行值(在TextView的),并执行列表的scoll,我失去了值(并返回我的第一次设置)!
例如,如果我创建50的TextView文本=示例1号一个ListView,如果我以后滚动列表中更改数值(onItemClick)TextView的值是例1号。
I have a problem with my listview! When I change the row value (on the textview) and execute a scoll of the list, I lost the values (and return on my first setting)! For example, if I create a listview with 50 textview with text = "Example no.1", if I change the value (onItemClick) after scroll list the textview value is "Example no.1".
这是我的例子code:
This is my example code:
.............................................
String sItems = new String[50];
HashMap<String,Object> personMap=new HashMap<String, Object>();
.............................................
sItems[iCnt] = "Example no.1";
personMap.put("title", sItems[iCnt]);
data.add(personMap);
.............................................
String[] from={"title"};
int[] to={R.id.rowTextView};
final SimpleAdapter adapter=new SimpleAdapter(getApplicationContext(),data,R.layout.all_textview,from,to);
final ListView listView = (ListView) findViewById(R.id.cd_sel_title_listview_textview);
listView.setAdapter((adapter));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
TextView textView = (TextView) v.findViewById(R.id.rowTextView);
textView.setText("Example No.2");
}
});
.............................................
在哪里我错了吗?
谢谢
Where i wrong? Thank you
推荐答案
试试这个:
public void onItemClick(AdapterView<?> arg0, View v, int position, long id)
{
TextView textView = (TextView) v.findViewById(R.id.rowTextView);
textView.setText("Example No.2");
personMap=new HashMap<String, Object>();
personMap.put("title", "Example No.2");
data.set(position,personMap);
}
这篇关于Android的ListView的滚动后丢失的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文