在android ListView中更新行内容
我有一个ListView,我需要在不重新加载所有ListView内容的情况下更新细节行的内容。此ListView可能很大 例如(对于DoItSimple),我需要更改位于适配器“x”位置的视图(行)中的TextView(适配器中的label3)的内容。实际上,我使用的是TouchListView(Commonware)适配器在android ListView中更新行内容,android,android-listview,Android,Android Listview,我有一个ListView,我需要在不重新加载所有ListView内容的情况下更新细节行的内容。此ListView可能很大 例如(对于DoItSimple),我需要更改位于适配器“x”位置的视图(行)中的TextView(适配器中的label3)的内容。实际上,我使用的是TouchListView(Commonware)适配器 类IconicAdapter扩展了ArrayAdapter{ 象似适配器(){ super(favoritesmainactive.this、R.layout.favbus
类IconicAdapter扩展了ArrayAdapter{
象似适配器(){
super(favoritesmainactive.this、R.layout.favbusrow、array);
}
公共视图getView(int位置、视图转换视图、视图组父视图){
视图行=转换视图;
LayoutInflater充气机=getLayoutInflater();
ListFav lf=(ListFav)array.get(position.getContent();
row=充气机。充气(R.layout.favrow,父项,false);
行.背景色(颜色.白色);
TextView标签=(TextView)row.findViewById(R.id.busNameF);
label.setText(lf.getName());
标签:setTextColor(颜色:黑色);
label.setTypeface(FontsManager.getBoldFont());
TextView label2=(TextView)row.findViewById(R.id.busNumberF);
label2.setText(lf.getNumber());
标签2.setTextColor(颜色为黑色);
label2.setTypeface(FontsManager.getBoldFont());
TextView label3=(TextView)row.findViewById(R.id.busDirectionF);
label3.setText(lf.getQuickName());
标签3.setTextColor(颜色为黑色);
label3.setTypeface(FontsManager.getRegularFont());
返回(行);
}
}
有人有主意吗
谢谢 更新适配器中的数据集以反映更改,然后在适配器上调用notifyDataSetChanged() 我需要更改位于适配器“x”位置的视图(行)中的TextView(适配器中的label3)的内容
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);
}
}
这一立场可能在眼前,也可能不在眼前。您可以使用getFirstVisiblePosition()
和getLastVisiblePosition()
查看是否存在,然后计算子索引并使用getChildAt()
检索行
您还需要确保您的数据模型反映了此更改,以便用户在滚动时不会“丢失”您所做的任何直接用户界面修改。您确实没有提供足够的信息来给出可靠的答案。名单长吗?您是否只更新这一个字段?您使用的是哪种适配器?可以访问行的内容吗?