Hi!
I have a listview with a customized ArrayAdapter. When the in the ArrayAdapter has changed the gui is supposed to update. However, when it's supposed to update, it won't unless you press a key on the emulator. The clickable rows are not clickable either unless i have clicked on an arbitrary button on the emulator. The underlying data for the listview is changed somewhere else and then notifying the observer (the listview in this case)
public void update(java.util.Observable arg0, Object arg1)
{
Log.e("Supposed","to update");
ad.notifyDataSetChanged(); //Ad is the arrayadapter
}
The data is presented properly after the magic touch on the buttons. But why? Any thoughts? When i inspect the ArrayAdapter's items-reference it shows the updated values, but the gui wont. Plz help
edit:
private class MustAdapter extends ArrayAdapter<Item>
{
public MustAdapter(Context context, int textViewResourceId, ArrayList<Item> items)
{
super(context,textViewResourceId,items);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Item o = items.get(position);
if (o != null) {
TextView tt = (TextView) v.findViewById(R.id.text1);
TextView bt = (TextView) v.findViewById(R.id.text2);
ImageView iv= (ImageView) v.findViewById(R.id.img);
ImageView ib = (ImageView)v.findViewById(R.id.OnOffButt);
if (ib != null) {
ib.setTag(position);
if (((Ventilation)o).enabled ==0 ) {
ib.setImageResource(android.R.drawable.ic_input_delete);
}
else
ib.setImageResource(android.R.drawable.ic_input_add);
ib.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
int index=((Integer)arg0.getTag()).intValue();
Ventilation v= (Ventilation)items.get(index);
v.enabled=v.enabled != 0 ? 0 : 1;
//ad.notifyDataSetChanged();
DU.toggle(v);
}
});
}
if (iv !=null){
iv.setImageResource(R.drawable.fan);
}
if (tt != null) {
tt.setText(""+((Ventilation)o).actual); }
if(bt != null){
bt.setText(""+((Ventilation)o).setPoint);
}
}
return v;
}
Even when i use arrayadapter.add(item) i have to press somewhere else for it to reload