我有两个 ListView,第二个视图项根据第一个用户在第一个 ListView 中选择的内容而变化
当用户首先从第一个列表中选择一个项目时,第二个 ListView 加载没有问题......但是当返回到第一个 ListView,选择另一个项目时,第二个 ListView 给出非法状态异常......
而且我不知道何时通知 ListView 有关 DataSetChanges,因为在 setListAdapter 之前或之后通知它是没有意义的!
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int mIndex = getIntent().getIntExtra("mIndex", 0);
adapter = new mListAdapter(this, getItems(mIndex));
setListAdapter(adapter);
}
更新: 我更改了适配器类,问题消失了......这是我的旧自定义类导致错误......知道它有什么问题吗?
mListAdapter 类
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;
}
}