I'm trying to inflate a layout in my getView method of my adapter:
Here is the error:
01-18 20:58:04.873: E/AndroidRuntime(21583): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView
01-18 20:58:04.873: E/AndroidRuntime(21583): at android.widget.AdapterView.addView(AdapterView.java:478)
01-18 20:58:04.873: E/AndroidRuntime(21583): at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
01-18 20:58:04.873: E/AndroidRuntime(21583): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
01-18 20:58:04.873: E/AndroidRuntime(21583): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
01-18 20:58:04.873: E/AndroidRuntime(21583): at com.myname.myapp.gui.MyAdapter.getView(MyAdapter.java:46)
The error (according to eclipse happens on the converView =mInflater...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = mInflater.inflate(
android.R.layout.simple_list_item_1, parent);
}
((TextView) convertView.findViewById(R.id.text1)).setText(titles
.get(position));
return convertView;
}
Here is the the constructor to my adapter:
public MyAdapter(ArrayList<String> list, Context context) {
titles = list;
this.context = context;
mInflater = LayoutInflater.from(context);
}