내가 만든 사용자 지정 ListAdapter를 사용하여 ListActivity의 내용을 새로 고치는 방법은 무엇입니까? 나는 arrayAdapter에 "notifyDataSetChanged();"라는 메서드를 가지고있다. 그건 작동하지 않습니다. 이 사이트에서 관련된 솔루션도 없습니다.이 ListActivity에서 정보를 업데이트하려면 어떻게해야합니까?
private final Activity context;
private Message[] messages;
public RamRSSAdapter(Activity context, Message[] messages) {
super(context, R.layout.ram_rss_row);
this.context = context;
this.messages = messages;
}
// static to save the reference to the outer class and to avoid access to
// any members of the containing class
static class ViewHolder {
public ImageView imageView;
public TextView textView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder will buffer the assess to the individual fields of the row
// layout
ViewHolder holder;
// Recycle existing view if passed as parameter
// This will save memory and time on Android
// This only works if the base layout for all classes are the same
View rowView = convertView;
//string code goes here
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.ram_rss_row, null, true);
holder = new ViewHolder();
holder.textView = (TextView) rowView.findViewById(R.id.label);
holder.imageView = (ImageView) rowView.findViewById(R.id.icon);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.textView.setText(messages[position].getTitle());
//code for image here
holder.imageView.setImageResource(getImageResID(getType(messages[position].getTitle())));
return rowView;
}
private String getType(String title){
int i1 = title.indexOf("[");
int i2 = title.indexOf("]");
if((i1==-1)||(i2==-1)){
return "";
}else{
return title.substring(i1+1, i2);
}
}
public void changeData(Message[] newData){
messages = newData;
notifyDataSetChanged();
}
/*
private int getImageResID(String type){
}
}
나는 그들을 찾았지만 찾을 수 없었다. ArrayAdapter의 내 하위 클래스가 전혀 인식하지 못했습니다. – user967514
이상한 점은 add, remove clear 및 insert는 API 레벨 1부터 사용할 수 있었고, addAll은 11 이후에만 사용할 수있었습니다. –