2011-05-01 163 views
0

後,我設置的ListView的適配器我需要的項目從一個線程如下更改的ListView項目

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 MyArrayAdapter(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(); 
} 

我的問題復位了項目沒有改變

回答

1

你必須改變你的模型,在你的情況下你綁定到適配器的列表。你正在做的是直接改變通常由適配器填充的TextView。但是,由於您不更改模型,適配器將覆蓋您對TextView所做的更改。

因此,改變模型,然後調用myAdapter.notifyDataSetChanged()。