Reputation: 15
Sorry for my English. I have my own ArrayAdapter
for list activity . My problem: when I take datas to web service , datas are added ArrayList
. Everything is normal up here. Nexus and Android OS 4.0 is listing the data, but other phone and 2.3.3 do not list the data. Everything is normal and I have not received any error.
I have no idea what's problem. Program listing data with Nexus(OS 4.0), but not listing in 2.3.3.
My Mobile Adapter class:
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> values;
public MobileArrayAdapter(Context context, ArrayList<String> values) {
super(context, R.layout.listlayout, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.listlayout, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
String s = values.get(position);
Log.d("Liste", "Liste " + values.get(position));
if (s != null && !s.equals("")) {
textView.setText(s);
}
// Change icon based on name
// String s = values[position];
return rowView;
}
}
Upvotes: 0
Views: 574
Reputation: 24464
That piece is bad:
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.listlayout, parent, false);
first, you don't use the view that was created for you by adapter, but always create a new one. Java machine will clean excessive objects, but it takes heaps of time. Second, ArrayAdapter can do all the work. Look here
Upvotes: 0
Reputation: 9791
Maybe after filling your list you should call adapter.notifyDataSetChanged()
?
Upvotes: 1