2011-11-01 59 views
3

我有一个ListView,我需要更新特定行的内容,而无需重新加载所有ListView内容。此ListView可以很大。更新Android中的行内容ListView

例如(为了简单起见)我需要更改位于适配器'x'位置的视图(行)中的TextView(适配器中的label3)的内容。其实我使用TouchListView(Commonsware)适配器。

class IconicAdapter extends ArrayAdapter<FavoriteObject> { 
    IconicAdapter() { 
     super(FavoritesMainActivity.this, R.layout.favbusrow, array); 
    } 

    public View getView(int position, View convertView,ViewGroup parent) { 
     View row=convertView; 
     LayoutInflater inflater=getLayoutInflater(); 

      ListFav lf = (listFav) array.get(position).getContent(); 

      row=inflater.inflate(R.layout.favrow,parent, false); 
      row.setBackgroundColor(Color.WHITE); 

      TextView label=(TextView)row.findViewById(R.id.busNameF); 
      label.setText(lf.getName()); 
      label.setTextColor(Color.BLACK); 
      label.setTypeface(FontsManager.getBoldFont()); 

      TextView label2 =(TextView)row.findViewById(R.id.busNumberF); 
      label2.setText(lf.getNumber()); 
      label2.setTextColor(Color.BLACK); 
      label2.setTypeface(FontsManager.getBoldFont()); 

      TextView label3 =(TextView)row.findViewById(R.id.busDirectionF); 
      label3.setText(lf.getQuickName()); 
      label3.setTextColor(Color.BLACK); 
      label3.setTypeface(FontsManager.getRegularFont()); 

     return(row); 
    } 
} 

有人有想法吗?

谢谢!

+0

您确实没有给出足够的信息以获得可靠的答案。名单很长吗?你只更新这一个领域?你使用什么样的适配器? –

+0

可以访问一行的内容吗? – Maxime

回答

1

我需要更改位于适配器'x'位置的视图(行)中的TextView(适配器中的label3)的内容。

该位置可能会或可能不在视图中。您可以使用getFirstVisiblePosition()getLastVisiblePosition()来查看它是否是,然后计算子索引并使用getChildAt()来检索该行。

您还需要确保您的数据模型反映了此更改,因此,当用户滚动时,他们不会“丢失”您所做的任何直接到用户界面的修改。

2

更新适配器中的数据集以反映您的更改,然后在适配器上调用notifyDataSetChanged()。