Change an item in ListView after setting its adupter
After I set the adapter of ListView I need to reset the item from a thread as following
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
listView = (ListView) findViewById(R.id.ListView01);
listView.setOnItemClickListener(this);
DirectoryBrowser dirBrowser= new DirectoryBrowser();
Vector<List<String>> fileCollection=dirBrowser.getList();
List<String> filesNames= fileCollection.elementAt(0);
List<String> filesDate= fileCollection.elementAt(1);
List<String> filesSize= fileCollection.elementAt(2);
filesPath= fileCollection.elementAt(3);
Log.d("swv file","swv file=" + filesDate.size());
final MyArrayAdapter myAdapter= new MyArrayAdapt开发者_JS百科er(this, filesNames,filesDate,filesSize);
int res=myAdapter.getCount();
listView.setAdapter(myAdapter);
myAdapter.notifyDataSetChanged();
Thread thread= new Thread(new Runnable() {
public void run() {
View rowView =myAdapter.getView(0, null, null);
ViewHolder holder = new ViewHolder();
holder.tv_name = (TextView) rowView.findViewById(R.id.label);
holder.tv_name.setText("dddddd");
myAdapter.notifyDataSetChanged();
}
});
thread.start();
myAdapter.notifyDataSetChanged();
}
My problem is item not changed
You must change your model, in your case the lists you bound to the adapter. What you are doing is changing directly the TextView which is normally populated by the adapter. But as you don't change the model the adapter will override the changes you made to the TextView.
So change the model and then call myAdapter.notifyDataSetChanged().
精彩评论