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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:23:42+00:00 2026-06-18T19:23:42+00:00

I have a custom ListView with a radiogroup in each row. When I change

  • 0

I have a custom ListView with a radiogroup in each row.
When I change the checked radio button, I call a dialog with some edittext fields (using the onCheckedChanged() method). But, when i focused an edittext to write something, I lose all the checked radiobuttons which are covered by keyboard, and the group returns to the default option selected.
can someone help me?

List adapter

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ContractItemHolder cih = new ContractItemHolder();
    if (row == null){
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(R.layout.row_proposals_item, parent, false);
        cih.setTvItemTitle((TextView)row.findViewById(R.id.textViewItemTitle));
        cih.setRgItemStatus((RadioGroup)row.findViewById(R.id.radioGroupStatus));

        row.setTag(cih);
    }else {
        cih=(ContractItemHolder)row.getTag();
    }
    final ContractItem ci = list.get(position);
    cih.getRgItemStatus().setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            groupSel = group;
            int selected = group.getCheckedRadioButtonId();
            Dialog d;
            switch (selected) {
            case R.id.radioAccepted:
                d = createDialog(context, ACCEPTED_CODE, ci, selected);
                d.show();
                break;
            case R.id.radioRefused:
                d = createDialog(context, REFUSED_CODE, ci, selected);
                d.show();
                break;
            default:
                break;
            }
        }
    });
    cih.getTvItemTitle().setText(ci.getDescItem());
    return row;
}

List item layout (the row..)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dp" 
    android:gravity="center">

    <TextView
        android:id="@+id/textViewItemTitle"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:layout_weight="3"
        android:textAppearance="?android:attr/textAppearanceLarge"/> 

    <RadioGroup
        android:id="@+id/radioGroupStatus"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:orientation="horizontal"
        android:layout_weight="1"
        android:showDividers="middle">

        <RadioButton
            android:id="@+id/radioNull"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Non Proposto" 
            android:checked="true"
            android:textAppearance="?android:attr/textAppearanceLarge"/>

        <RadioButton
            android:id="@+id/radioPending"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="In trattativa" 
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/Blue"/>

        <RadioButton
            android:id="@+id/radioAccepted"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Accettato" 
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/Green"/>

        <RadioButton
            android:id="@+id/radioRefused"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rifiutato" 
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/Red"/>

    </RadioGroup> 

</LinearLayout>

Dialog impl

private Dialog createDialog(Context context, final int code, ContractItem item,final int selected){ //type: refused, accepted
    d = new Dialog(context);
    d.setTitle(item.getDescItem());
    d.setContentView(R.layout.layout_dialog_prop);
    d.getWindow().setLayout(900, LayoutParams.WRAP_CONTENT);
    d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

    Button btnOK = (Button)d.findViewById(R.id.buttonPropOK);
    Button btnCancel = (Button)d.findViewById(R.id.buttonPropCancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            d.dismiss();
        }
    });
    btnOK.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            d.dismiss();

        }
    });
    return d;
}

Dialog layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="50dp" >

        <EditText
            android:id="@+id/editTextDiscount"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:ems="10"
            android:hint="Sconto proposto"
            android:inputType="number"
            android:textAppearance="?android:attr/textAppearanceLarge" >

            <requestFocus />
        </EditText>

        <Spinner
            android:id="@+id/spinnerScuse"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dp"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:visibility="gone" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="30dp"
            android:ems="10"
            android:gravity="top"
            android:hint="Note"
            android:inputType="textMultiLine"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    </LinearLayout>

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginTop="30dp"
        android:background="@android:color/holo_blue_light" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/buttonPropCancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:text="Annulla"
            android:textColor="@android:color/holo_blue_light" />

        <View
            android:id="@+id/view1"
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@android:color/holo_blue_light" />

        <Button
            android:id="@+id/buttonPropOK"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:text="Ok"
            android:textColor="@android:color/holo_blue_light" />

    </LinearLayout>

</LinearLayout>
  • 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-18T19:23:44+00:00Added an answer on June 18, 2026 at 7:23 pm

    You are partially aware of the list-item view recycling process.

    The ListView component doesn’t generate view for each item in the list. So, there won’t be 15 of them in your case. There will be just as many as can fit on the screen. When you scroll the list, the old items, which are no longer visible, are recycled. The getView is then called with convertView != null and the adapter is giving you an opportunity to update this recycled item view. This is done for performance reasons – just imagine an adapter having 10000 items (not a rare thing in commercial applications). Should it create all 10000 list item views? Imagine the performance you would have while scrolling such a list…

    In your getView() code, you update an item view only partially – you always set item title in this line:

    cih.getTvItemTitle().setText(ci.getDescItem());
    

    When an fresh item view is created (i.e. the convertView == null) the radio group has a default selection, which may be fine in your case.

    However, when the item view is recycled (i.e. the convertView != null), then you:

    • set a change listener in this line:

      cih.getRgItemStatus().setOnCheckedChangeListener(...);
      
    • set item title:

      cih.getTvItemTitle().setText(ci.getDescItem());
      

    But you never set the checked radio group item. That means, it will have a value which was last set for this instance of item view – not for that position. You should store that information – probably in ContractItem, update it when the radio group item is selected and finally – retrieve it when convertView != null and set selected item of the radio group to the correct value.

    You probably see this defect when you open up a dialog – the visible area of a ListView becomes smaller as the soft keyboard opens. This causes the ListView to remove unnecessary (technically: no longer visible) item views. When you hide the soft keyboard, the ListView area becomes larger again thus causing it to create missing item views. Unfortunately, you don’t save and restore the last selected item of the radio group and so, after creation the newly visible items have the default item selected in the radio group.

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

Sidebar

Related Questions

I have a custom listview and a radio button in each row, it works
I have a custom listView with editText in each row to carry value entered
I have a custom listview which display an image, textview and radio button. I
I have a custom listview, each cell has 5 textviews and 2 button. Somehow
I have a custom listView with a textView, editText and a Button on a
I have sectioned custom ListView that contains RadioButton on each items. When a Dialog
I have a custom ListView where each row consists of a number of TextViews
I have created custom listview, each row looks like my file custom_row.xml. Is there
I have a custom ListView in which each row.xml looks like this: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a custom ListView with two button and I when I click either

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.