2013-08-01 54 views
0

我有自定義適配器的自定義列表視圖。自定義列表視圖由圖像和兩個文本視圖組成,可以說textViewA和textViewB。現在我想在自定義列表視圖的每一行中更改textViewB的文本,而不更新其他組件。我的第一個問題是可能的嗎?如果是的話,我該怎麼做。Android:如何更新自定義ListView的組件

回答

0

您是否試過將String[]參數傳遞給您的適配器?例如:

public class CustomAdapter extends BaseAdapter { 

    String[] data_text; 

    CustomAdapter() { 

    } 

    CustomAdapter(String[] text) { 
     data_text = text; 
    } 

    CustomAdapter(ArrayList<String> text) { 

     data_text = new String[text.size()]; 

    for (int i = 0; i < text.size(); i++) { 
     data_text[i] = text.get(i); 
    } 

    } 

    @Override 
    public int getCount() { 
     return data_text.length; 
    } 

    @Override 
    public String getItem(int position) { 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     LayoutInflater inflater = getLayoutInflater(); 
     View row; 

     row = inflater.inflate(R.layout.drawer_list_item, parent, false); 

     TextView textview = (TextView) row.findViewById(R.id.text1); 

     textview.setText(data_text[position]); 

    return (row); 

    } 

} 
0

您必須調用notifyDataSetChanged()並更改適配器中的textview值。

0
listView.setadaptor(null); 
// do what ever methods here to change your data, strings objects, etc 
listview.notifyDataSetChanged();