so, i'm creating an expandable list, each group header has a star icon (image button) on the right side and can be pressed to indicate whether it is favorite or not. I need to assign id to each star to indicate which one is favorite and which one is not. when i'm using setId(), it returns nullpointerexception. what have I done wrong and what can I do give each star an ID? thank you :)
public int count=0;
@Override
public View getGroupView(final int groupPosition, boolean isExpanded,View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
lblListHeader.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
mActivity.expandGroup(groupPosition);
}
});
final ImageButton button = (ImageButton) convertView.findViewById(R.id.favoritelist_button);
button.setId(count);
count=count+1;
button.setImageResource(R.drawable.phone);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(!tFave){
button.setImageResource(R.drawable.phone);
tFave = true;
}
else{
button.setImageResource(R.drawable.gmail);
tFave = false;
}
}
});
return convertView;
}