M
masterkot
Neues Mitglied
- 0
Hallo zusammen,
ich habe einen ListView mit einem eigenen Adapter:
Adapter:
ListView füllen:
Jetzt muss ich teils den ListView neu laden, da er neue Daten enthalten soll. Wie kann ich das machen?
Google sagt immer, dass man 'adapter.notifyDataSetChanged();' ausführen soll, das klappt aber leider nicht
Kann mir jemand helfen?
Vielen Dank und Gruß
Mats
ich habe einen ListView mit einem eigenen Adapter:
Adapter:
Code:
public class MenuAdapter extends ArrayAdapter<String> {
private final Context context;
private String[] Ids;
private final int rowResourceId;
public MenuAdapter(Context context, int textViewResourceId, String[] objects) {
super(context, textViewResourceId, objects);
this.context = context;
this.Ids = objects;
this.rowResourceId = textViewResourceId;
}
public void updateAdapter(String[] Id){
this.Ids = Id;
this.notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(rowResourceId, parent, false);
ImageView imageView = (ImageView) rowView.findViewById(R.id.imageView);
TextView textView = (TextView) rowView.findViewById(R.id.textView);
int id = Integer.parseInt(Ids[position]);
String imageFile = Config.GetbyId(id).IconFile;
textView.setText(Config.GetbyId(id).Name);
// get input stream
InputStream ims = null;
try {
ims = context.getAssets().open(imageFile);
} catch (IOException e) {
e.printStackTrace();
}
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, null);
// set image to ImageView
imageView.setImageDrawable(d);
return rowView;
}
ListView füllen:
Code:
public void loadMenu() {
Config.LoadModel();
final String[] ids = new String[Config.menu.size()];
for (int i= 0; i < ids.length; i++){
ids[i] = Integer.toString(i+1);
}
adapter = new MenuAdapter(this,R.layout.listrow, ids);
menuListView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
Jetzt muss ich teils den ListView neu laden, da er neue Daten enthalten soll. Wie kann ich das machen?
Google sagt immer, dass man 'adapter.notifyDataSetChanged();' ausführen soll, das klappt aber leider nicht

Kann mir jemand helfen?
Vielen Dank und Gruß
Mats