I have two ListViews, the second view items change according to what the first user chose in the first ListView
When at first the user choose an item from the first list, the second ListView loads without a problem… but when going back to the first ListView, selecting another item, the second ListView gives the Illegal State Exception…
and I have no idea when to notify the ListView about DataSetChanges because it doesn’t make sense to notify it before or after the setListAdapter!
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int mIndex = getIntent().getIntExtra("mIndex", 0);
adapter = new mListAdapter(this, getItems(mIndex));
setListAdapter(adapter);
}
Update:
I changed the adapter class and the problem disappeared… This is my old custom class that caused the error… Any idea what is wrong with it?
mListAdapter Class
public class mListAdapter extends BaseAdapter {
private static ArrayList<mItemsHolder> arrayList;
private LayoutInflater mInflater;
Context context;
int textSize;
public mListAdapter (Context m_context, ArrayList<mItemsHolder> results, int mTextSize) {
arrayList = results;
mInflater = LayoutInflater.from(m_context);
context = m_context;
textSize = mTextSize;
}
public int getCount() {
return arrayList.size();
}
public Object getItem(int position) {
return arrayList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row, null);
holder = new ViewHolder();
holder.mainItem = (TextView) convertView.findViewById(R.id.row_txt_main);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Typeface typeFace=Typeface.createFromAsset(context.getAssets(),"fonts/verdana.ttf");
holder.mainItem.setText(arrayList.get(position).getMainItem());
holder.mainItem.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
holder.mainItem.setTypeface(typeFace);
return convertView;
}
static class ViewHolder {
TextView mainItem;
}
}
I just removed “static” when declaring my ArrayList in