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 8616325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:35:29+00:00 2026-06-12T05:35:29+00:00

I am creating a android app the UI of my application is below given.

  • 0

I am creating a android app the UI of my application is below given.

On clicking of submit button, I need the selected check box, and radio buttons value.

Example Linux is not checked, cc(radio button) is checked.

Records are populated dynamically in list view, but I am not able to make it work. A lot of
problems are there.

  1. When I scroll the list view radio button gets automatically selected or deselected not able to maintain the state of radio button.
  2. On click of button not getting the selected radio button as well as check box.

Below is my layout as well as java program. Suggest me to get the correct values.

application image

Main.xml

<ListView
    android:id="@+id/my_list"
    android:layout_width="fill_parent"
    android:layout_height="199dp" />

<Button
    android:id="@+id/submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Submit"
    />

row.xml

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@+id/label"
    android:layout_toRightOf="@+id/check"
    android:textSize="20sp" >
</TextView>

<CheckBox
    android:id="@+id/check"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="4dip"
    android:layout_marginRight="10dip"
    android:focusable="false"

    android:focusableInTouchMode="false" >
</CheckBox>

 <RadioGroup
     android:id="@+id/radioSex"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:layout_alignParentRight="true"
     android:layout_alignParentTop="true"
     android:orientation="horizontal" >

     <RadioButton
         android:id="@+id/to"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
         android:checked="true"
         android:text="To" />

     <RadioButton
         android:id="@+id/cc"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="10dip"
         android:text="CC" />
 </RadioGroup>

MyAdaptor.java

public class MyAdapter extends ArrayAdapter<Model> {

    private final List<Model> list;
    private final Activity context;
    boolean checkAll_flag = false;
    boolean checkItem_flag = false;

    public MyAdapter(Activity context, List<Model> list) {
        super(context, R.layout.row, list);
        this.context = context;
        this.list = list;
    }

    static class ViewHolder {
        protected TextView text;
        protected CheckBox checkbox;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            LayoutInflater inflator = context.getLayoutInflater();
            convertView = inflator.inflate(R.layout.row, null);
            viewHolder = new ViewHolder();
            viewHolder.text = (TextView) convertView.findViewById(R.id.label);
            viewHolder.checkbox = (CheckBox) convertView
                    .findViewById(R.id.check);

            viewHolder.checkbox
                    .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView,
                                boolean isChecked) {
                            int getPosition = (Integer) buttonView.getTag();
                            list.get(getPosition).setSelected(
                                    buttonView.isChecked());
                        }
                    });
            convertView.setTag(viewHolder);
            convertView.setTag(R.id.label, viewHolder.text);
            convertView.setTag(R.id.check, viewHolder.checkbox);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.checkbox.setTag(position);

        viewHolder.text.setText(list.get(position).getName());
        viewHolder.checkbox.setChecked(list.get(position).isSelected());

        return convertView;
    }

MainActivity.java

public class MainActivity extends Activity implements OnItemClickListener {

    ListView listView;
    ArrayAdapter<Model> adapter;
    List<Model> list = new ArrayList<Model>();

    private RadioGroup radioCcToGroup;
    private RadioButton radioTypeButton;
    private Button btn;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        listView = (ListView) findViewById(R.id.my_list);

        btn = (Button) findViewById(R.id.submit);

        btn.setOnClickListener(new View.OnClickListener() {
            int count = 0;

            @Override
            public void onClick(View view) {


                count = listView.getAdapter().getCount();
                for (int i = 0; i < count; i++) {
                    // here i am not able to get the records as getting on onItemClick of the listview
                }
            }
        });

        adapter = new MyAdapter(this, getModel());
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
        TextView label = (TextView) v.getTag(R.id.label);
        CheckBox checkbox = (CheckBox) v.getTag(R.id.check);
        Toast.makeText(v.getContext(),
                label.getText().toString() + " " + isCheckedOrNot(checkbox),
                Toast.LENGTH_LONG).show();

    }

    private String isCheckedOrNot(CheckBox checkbox) {
        if (checkbox.isChecked())
            return "is checked";
        else
            return "is not checked";
    }

    private List<Model> getModel() {
        list.add(new Model("Linux"));
        list.add(new Model("Windows7"));
        list.add(new Model("Suse"));
        list.add(new Model("Eclipse"));
        list.add(new Model("Ubuntu"));
        list.add(new Model("Solaris"));
        list.add(new Model("Android"));
        list.add(new Model("iPhone"));
        list.add(new Model("Java"));
        list.add(new Model(".Net"));
        list.add(new Model("PHP"));
        return list;
    }

Model.java

private String name;
    private boolean selected;

    public Model(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }
  • 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-06-12T05:35:30+00:00Added an answer on June 12, 2026 at 5:35 am

    You got 2 mistakes here both on your MyAdaptor.java :

    1. When you attach the onCheckedChangeListener you do it only when a new view needs to be created and you forget the case where the list view reuses the view. You should setOnCheckedChangeListener outside if (convertView == null).

    2. It seems that onCheckedChangeListener is called also when the scroll is done (because of viewHolder.checkbox.setChecked(list.get(position).isSelected());). You can avoid this by using OnClickListener over viewHolder.checkbox or not calling viewHolder.checkbox.setChecked().

    Here is my code:

    private class ViewHolder {
        protected TextView text;
        protected CheckBox checkbox;
        protected RadioGroup radioGroup;
    }
    
    public class MyAdapter extends ArrayAdapter<Model> {
    
        private final List<Model> list;
        private final Activity context;
        boolean checkAll_flag = false;
        boolean checkItem_flag = false;
    
        public MyAdapter(Activity context, List<Model> list) {
            super(context, R.layout.row, list);
            this.context = context;
            this.list = list;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            ViewHolder viewHolder = null;
            if (convertView == null) {
                LayoutInflater inflator = context.getLayoutInflater();
                convertView = inflator.inflate(R.layout.row, null);
    
                viewHolder = new ViewHolder();
                viewHolder.text = (TextView) convertView.findViewById(R.id.label);
                viewHolder.checkbox = (CheckBox) convertView.findViewById(R.id.check);
                viewHolder.checkbox.setTag(position);
                viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioSex);
                viewHolder.radioGroup.setTag(position);
    
                convertView.setTag(viewHolder);
            } else {
                viewHolder = (ViewHolder) convertView.getTag();
            }
    
            viewHolder.text.setText(list.get(position).getName());
            viewHolder.checkbox.setChecked(list.get(position).isSelected());
            viewHolder.checkbox.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    CheckBox checkbox = (CheckBox) v;
                    int getPosition = (Integer) checkbox.getTag();
                    list.get(getPosition).setSelected(checkbox.isChecked());
                }
            });
    
            viewHolder.radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    boolean isCcOrIsTo = (checkedId == R.id.cc);
                    int getPosition = (Integer) group.getTag();
                    list.get(getPosition).setCcOrIsTo(isCcOrIsTo);
                }
            });
    
            return convertView;
        }
    }
    

    Notice i’ve added some control over the radiogroup too, so Model.java has changed:

    public class Model {
    
        private String name;
        private boolean selected;
        private boolean isCcOrIsTo;
    
        public Model(String name) {
            this.name = name;
        }
    
        public String getName() {
            return name;
        }
    
        public boolean isSelected() {
            return selected;
        }
    
        public void setSelected(boolean selected) {
            this.selected = selected;
        }
    
        public boolean isCcOrIsTo() {
            return isCcOrIsTo;
        }
    
        public void setCcOrIsTo(boolean isCcOrIsTo) {
            this.isCcOrIsTo = isCcOrIsTo;
        }
    
        @Override
        public String toString() {
            String selectedString = selected ? "selected" : "not selected";
            String value = isCcOrIsTo ? "CC" : "To";
            return name+" -> "+selectedString+ " with value "+value;
        }
    }
    

    Finally you don’t need onItemClick on MainActivity.java, to check if the values are correct when you click the summit button :

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_main);
    
        listView = (ListView) findViewById(R.id.my_list);
    
        btn = (Button) findViewById(R.id.submit);
    
        btn.setOnClickListener(new View.OnClickListener() {
    
            @Override
            public void onClick(View view) {
                for (Model m : list) {
                    Log.i("Stack1", m.toString());
                }
            }
        });
    
        ArrayAdapter<Model> adapter = new MyAdapter(this, getModel());
        listView.setAdapter(adapter);
    }
    

    Hope it helps 😉

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

Sidebar

Related Questions

I'm creating Android application contains 2 buttons, on click on each button play a
I am creating a web application (completely running on the server, no Android App
I'm creating my first android app and I need to use a service. The
When creating an android app, we need to supply a package name in the
Suppose I am creating an Android application that's like an SMS app. The requirements
We are creating many XML files for a single app in developing android applications;
I'm creating an Android app which must do some web surfing in the background
I am creating an android app myself (min sdk version 7 or 2.1 and
I am creating an Android app based on The Legend of Zelda, I wanted
so here is the problem. I am currently creating an Android app that is

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.