Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:09:32+00:00 2026-05-31T07:09:32+00:00

I have a custom ListView with the first four elements being buttons. When I

  • 0

I have a custom ListView with the first four elements being buttons. When I click a button it goes into a new activity, I do whatever in the new activity, and then return. When I return, I want the button that I hit to be checked off, however sometimes (and only sometimes) it checks off the wrong box and i can’t figure out why. Here is my code for my custom Adapter:

private class MyCustomAdapter extends BaseAdapter {
    private static final int TYPE_BUTTON = 0;
    private static final int TYPE_INFO = 1;
    private static final int TYPE_PICTURE = 2;
    private static final int TYPE_MAX_COUNT = 3;
    private int totalCount = 0;
    private ArrayList<String> mData = new ArrayList<String>();
    private LayoutInflater mInflater;

    public MyCustomAdapter() {
        mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public void addButton(final Button btn) {
        mButtons.add(btn);
        totalCount = totalCount + 1;
        notifyDataSetChanged();
    }

    public void addInfo(final String info) {
        mInfo.add(info);
        totalCount = totalCount + 1;
        notifyDataSetChanged();
    }

    public void addPicture(final Bitmap pic) {
        mPictures.add(pic);
        totalCount = totalCount + 1;
        notifyDataSetChanged();
    }

    public void addItem(final String item) {
        mData.add(item);
        totalCount = totalCount + 1;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return totalCount;
    }

    @Override
    public String getItem(int position) {
        return "TEST 5000";
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        if (position <= 3) {
            return TYPE_BUTTON;
        }
        if (mInfo.size() + 3 >= position) {
            return TYPE_INFO;
        } else {
            return TYPE_PICTURE;
        }
    }

    @Override
    public int getViewTypeCount() {
        return TYPE_MAX_COUNT;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        System.out.println("getView " + position + " " + convertView);
        ViewHolder holder = null;
        int type = getItemViewType(position);
        if (convertView == null) {
            holder = new ViewHolder();
            switch (type) {
                case TYPE_BUTTON:
                    convertView = mInflater.inflate(R.layout.button, null);
                    holder.btn = (Button)convertView.findViewById(R.id.btn);
                    holder.btn.setText(mButtons.get(position).getText().toString());
                    holder.btn.setLayoutParams(new LinearLayout.LayoutParams(mButtons.get(position).getLayoutParams().width, mButtons.get(position).getLayoutParams().height));
                    break;
                case TYPE_INFO:
                    convertView = mInflater.inflate(R.layout.incident_summary_items, null);
                    holder.textView = (TextView)convertView.findViewById(R.id.text);
                    holder.textView.setText(mInfo.get(position-4));
                    break;
                case TYPE_PICTURE:
                    convertView = mInflater.inflate(R.layout.image, null);
                    holder.imageView = (ImageView)convertView.findViewById(R.id.pic);
                    holder.imageView.setImageBitmap(mPictures.get(position-4-mInfo.size()));
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
            switch(type) {
                case TYPE_BUTTON:
                    holder.btn.setText(mButtons.get(position).getText().toString());
                    holder.btn.setLayoutParams(new LinearLayout.LayoutParams(mButtons.get(position).getLayoutParams().width, mButtons.get(position).getLayoutParams().height));
                    break;
                case TYPE_INFO:
                    holder.textView.setText(mInfo.get(position-4));
                    break;
                case TYPE_PICTURE:
                    holder.imageView.setImageBitmap(mPictures.get(position-4-mInfo.size()));
                    break;
            }
        }
        return convertView;
    }

}

public static class ViewHolder {
    public TextView textView;
    public ImageView imageView;
    public Button btn;
}

and here is my code where i set the checkbox and call the new activity:

public void myClickHandler(View v)
{
    //get the row the clicked button is in
    vwParentRow = (LinearLayout)v.getParent();

    btnChild = (Button)vwParentRow.getChildAt(0);


    if (btnChild.getText().toString().equals("Take Information")) {
        btnChild.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckMark,null);
        Intent intent = new Intent(this, Info.class);
        startActivityForResult(intent, 1);
    }

    if (btnChild.getText().toString().equals("Take Pictures")) {
        btnChild.setCompoundDrawablesWithIntrinsicBounds(null,null,mCheckMark,null);
        Intent intent = new Intent(this, Pictures.class);
        startActivityForResult(intent, 2);
    }
}

I found if i commented out the lines

holder.btn.setText(mButtons.get(position).getText().toString());
holder.btn.setLayoutParams(new LinearLayout.LayoutParams(mButtons.get(position).getLayoutParams().width, mButtons.get(position).getLayoutParams().height));

in the else statement of my custom List Adapter, the checklist checked the correct button, but the buttons would change order in the list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:09:33+00:00Added an answer on May 31, 2026 at 7:09 am

    As your using startActivityForResult for new activity you can return the value from that and on your parent where your buttons are use onResume to set the button status as disabled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listView with custom rows containing buttons and I populate the listView
I have a custom listview which display an image, textview and radio button. I
I have an activity with listview and attached footer. I created my custom adapter
I have a listView with custom objects defined by the xml-layout below. I want
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have trouble getting a custom ObjectDataSource for an asp:ListView control to work. I
I have a listview with 200 items. I use a custom view for each
I have two ItemsControls, one a ListView, and one a custom control I am
i have custom cell with 2 buttons(the function of these buttons is just to
I have a listview with a custom arrayadapter that handles about 15 strings. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.