Android : CustomListViewAdapter having illegalStateException

on Monday, July 7, 2014


I am working on CustomListViewAdapter currently, and here's the extract of the getView method in my code in CustomListViewAdapter.java. I think the problem lies on here, mostly probably in the line { final View view = super.getView(...) }, as I have used the debug mode for testing. How to solve it?


Description: what I want to do is, when AND only when clicked on the switchImage in the row, the corresponding switchImage and lockImage change their images. I have tried, but OnItemClickListener in my MainActivity.class doesnt allow me to specify that only when clicking switchImage would the effect appear (effect appears once clicking on ANY items in the row).


THX for any helps and comments.



@Override
public View getView(int position, View convertView, ViewGroup parent) {
final View view = super.getView(position, convertView, parent);
final ImageView switchImage = (ImageView) view.findViewById(R.id.onOffSwitch);
final ImageView lockImage = (ImageView) view.findViewById(R.id.lock);
switchImage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if (flag == false) {
flag = true;
...
...
...
}
}
});

RowItem rowItem = getItem(position);

if (convertView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
holder.lock = (ImageView) convertView.findViewById(R.id.lock);
holder.appName = (TextView) convertView.findViewById(R.id.appName);
...
...
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}

holder.lock.setImageResource(rowItem.getLockId());
...
...
return view;
}

0 comments:

Post a Comment