0

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;
    }
user3158109
  • 41
  • 1
  • 4
  • post the xml layout also – Raghunandan Jan 03 '14 at 17:51
  • my application is to list Korean word that has been favorited. the expandable list will be like: AAAAA- verb- eat (star button) BBBBB- verb- sleep (star button) the star button can be pressed if the user doesn't want to keep the favorite word anymore. so, i have to assign ID to the star button so I know which one has been unfavorited and I can remove that word from database.. – user3158109 Jan 03 '14 at 17:56

0 Answers0