Rectangle 27 7

One way is to manually uncheck all others radiobuttons. You can create variable that will keep position of currently selected item. And in getView you check/uncheck current radio button depending on whether current position equals to selected one. When use press radio button you change position of selected item and call notifyDatasetChanged. Also check this quesion: Android ListView with RadioButton in singleChoice mode and a custom row layout

private int selected = -1
CitizenAdapter
holder.radioCitizen.setOnClickLisener(new View.OnClickListener() 
    {                              
        @Override
        public void onCheckedChanged(View view) {
            selected = (Integer) view.getTag();
            notifyDataSetChanged();
        }
    });
// After you set text to 4 textviews
holder.radioButCitizen.setTag(position);
holder.radioButCitizen.setChecked(position == selected);

at the accepted answer on that link, there is again some explanation like this, can u specify some code? thanks

Using radio button in custom listview in Android - Stack Overflow

android android-listview radio-button
Rectangle 27 7

I have tested a simpler solution:

Add this line in the RadioButton of your xml file:

<RadioButton 
   ...
   android:onClick="onClickRadioButton"
   ...
/>

Then in the activity class that uses the ListView, add the following:

private RadioButton listRadioButton = null;
   int listIndex = -1;

   public void onClickRadioButton(View v) {
        View vMain = ((View) v.getParent());
        // getParent() must be added 'n' times, 
        // where 'n' is the number of RadioButtons' nested parents
        // in your case is one.

        // uncheck previous checked button. 
        if (listRadioButton != null) listRadioButton.setChecked(false);
        // assign to the variable the new one
        listRadioButton = (RadioButton) v;
        // find if the new one is checked or not, and set "listIndex"
        if (listRadioButton.isChecked) {
            listIndex = ((ViewGroup) vMain.getParent()).indexOfChild(vMain); 
        } else {
            listRadioButton = null;
            listIndex = -1
        }
    }

With this simple code only one RadioButton is checked. If you touch the one that is already checked, then it returns to the unchecked mode.

"listIndex" is tracking the checked item, -1 if none.

If you want to keep always one checked, then code in onClickRadioButton should be:

public void onClickRadioButton(View v) {
        View vMain = ((View) v.getParent());
        int newIntex = ((ViewGroup) vMain.getParent()).indexOfChild(vMain);
        if (listIndex == newIndex) return;

        if (listRadioButton != null) {
                listRadioButton.setChecked(false);
        }
        listRadioButton = (RadioButton) v;
        listIndex = newIndex; 
    }

Hi,this works when the list fits in 1 page, but when the list is longer than a page, listIndex gets messed up as it starts counting from the first visible list item rather than from the actual start of the list. How can this be fixeD?

Android ListView with RadioButton in singleChoice mode and a custom ro...

android listview radio-button listviewitem
Rectangle 27 0

CheckBox cv =(CheckBox)v.findViewById(R.id.checktitle)

Your trying to get the checkbox associated with "v", but findViewById() doesn't do that. Instead your just creating a NEW checkbox from your XML.

I think what you want to do is modify the underlying data "dcates" and then call notifyDataSetChanged() on your adapter.

for (CustomDishMenus menu : dcates)
    menu.setSelected(false);

listview.getAdapter().notifyDataSetChanged();

uncheck all checbox in listview in android - Stack Overflow

android listview checkbox uncheck
Rectangle 27 0

In your adapter (customAdapter) include a method call setAllSelected();

setAllSelected () {
    for (int i = 0; i < this.getCount(); i++) {
        AdapterItem info = this.getItem(i);

        // info (add a boolean in you adapter item to store the state of checkbox i.e. isSelected and mark it to true. )
    }
    notifyDataSetChanged();
}

In your getView(). according to state of variable(isSelected), select or deselect the checkbox.

Steve B i want to reset all listview checkbox so i have a button..and in button listener how can i call the method as u mention uncheckAllChildrenCascade(Viewgroup) but in button listener we have only a view how can i call the method uncheckAllChildrenCascade(ViewGroup v)?Your answer is pretty much clear but how can i call this?

paul this is in my button listener CheckBox cv =(CheckBox)v.findViewById(R.id.checktitle) this line is written in the button listener and above code is also written in button listener.. setOnClickListener..

uncheck all checbox in listview in android - Stack Overflow

android listview checkbox uncheck
Rectangle 27 0

protected void Page_Load(object sender, EventArgs e)
    { 
      pdfPagesListView.DataSource="";
      pdfPagesListView.DataBind();
    }

In that case you need to check whether your selectAllPages is Checked or not at DataBound Event of your Listview.

c# - chech/uncheck all checkboxes in ListView with onItemDataBound - S...

c# asp.net listview checkbox itemdatabound
Rectangle 27 0

One way is to manually uncheck all others radiobuttons. You can create variable that will keep position of currently selected item. And in getView you check/uncheck current radio button depending on whether current position equals to selected one. When use press radio button you change position of selected item and call notifyDatasetChanged. Also check this quesion: Android ListView with RadioButton in singleChoice mode and a custom row layout

private int selected = -1
CitizenAdapter
holder.radioCitizen.setOnClickLisener(new View.OnClickListener() 
    {                              
        @Override
        public void onCheckedChanged(View view) {
            selected = (Integer) view.getTag();
            notifyDataSetChanged();
        }
    });
// After you set text to 4 textviews
holder.radioButCitizen.setTag(position);
holder.radioButCitizen.setChecked(position == selected);

at the accepted answer on that link, there is again some explanation like this, can u specify some code? thanks

Using radio button in custom listview in Android - Stack Overflow

android android-listview radio-button
Rectangle 27 0

set your listview choice mode to single choice and declare global integer variable with value -1.

int cPos=-1;

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    listView.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    // TODO Auto-generated method stub

                    if (cPos == position) {
                        if(listView.isItemChecked(cPos)){
                            listView.setItemChecked(position, false);   
                        }else{
                            listView.setItemChecked(position, true);
                        }
                    } else {
                        listView.setItemChecked(position, true);
                    }
                    cPos = listView.getCheckedItemPosition();

                }
            });

android - How to uncheck the already selected checkedtextview in sigle...

android android-listview checkedtextview
Rectangle 27 0

public View getView(int position, View convertview, ViewGroup arg2) {
    if (convertview == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertview = (RelativeLayout) inflater.inflate(
                R.layout.images_gridview, null);
    }
    ImageView gridImage = (ImageView) convertview.findViewById(R.id.image);
    CheckBox checkBox = (CheckBox) convertview.findViewById(R.id.checkBox1);
    checkBox.setTag(position);
    if (photos.get(position).isSelected()) {
        checkBox.setChecked(true);
    }
    WindowManager manager = (WindowManager) context
            .getSystemService(Activity.WINDOW_SERVICE);
    int width;
    if (Build.VERSION.SDK_INT > VERSION_CODES.FROYO) {
        width = manager.getDefaultDisplay().getWidth();
    } else {
        Point point = new Point();
        manager.getDefaultDisplay().getSize(point);
        width = point.x;
    }

    LayoutParams params = new LayoutParams(width / 3, width / 3);
    gridImage.setLayoutParams(params);
    gridImage.setImageURI(Uri.parse(photos.get(position)
            .getThumbnilImageUrl()));
    checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkedButton,
                boolean checked) {
            if (checked) {
                selectedPhotos.add(photos.get((Integer) checkedButton
                        .getTag()));
                photos.get((Integer) checkedButton.getTag()).setSelected(
                        true);
            } else {
                selectedPhotos.remove(photos.get((Integer) checkedButton
                        .getTag()));
                photos.get((Integer) checkedButton.getTag()).setSelected(
                        false);
            }
        }
    });

    return convertview;
}

if (photos.get(position).isSelected()) instead of photos what i want to write!!i m new to android..

For you its not required if you maintaing any class objects then it is required..for maintaing listitems which have selected and non selected maintain one class with two variables one string and one boolean value..set string to your listview textvitew..change the boolean when selected

How to seperate the Listview with Check and Uncheck items Android? - S...

android listview scrollview android-linearlayout
Rectangle 27 0

lstAttribs.clearChoices()

android - How to uncheck the already selected checkedtextview in sigle...

android android-listview checkedtextview
Rectangle 27 0

You could save the ID of the currently checked item in a variable. Then, when another item is checked (inside the listener) you simply uncheck the old one and change the variable to the new ID.

I'm a bit confused by your mCheckedStates. Probably you could just change mCheckedStates.put(...) to .set(...) in onCheckedChange (seems to me like you're adding a new entry with every click.) If that doesn't help, you can save the position of the checked item (as i said) but that has to handled inside getView(int position,...).

mCheckedStates will add position at a SparseBooleanArray and get when click check in DownloadActivity. You see in method btnChecked.setOnClickListener. I don't see set(...) in method mCheckedStates :). Oke I'll try to figure out how to solve

android - Automatic uncheck checkboxes when change check in listview -...

android listview checkbox android-listview
Rectangle 27 0

You can build your own class that consists of the listview elemnt's field and add one more field (isChecked). When you recreate adapter, you use already created objects and checked state is saved and in the getview of each row you can check\uncheck this item by this property

Here is my custom checkbox, you can use it and modify if you want, i think it can fit you purposes (i take this code as is from my app and you can check how it works in this app):

package ru.human.notification;


import java.util.ArrayList;

import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckedTextView;

public class CustomCheckBox extends CheckedTextView
{

    private int CHECKED_IMAGE;
    private int UNCHECKED_IMAGE;
    private main_full parent;
    private ArrayList<View> viewsToCheck;
    private int msgType;

    public void setParent(main_full parent, int msgType)
    {
        this.parent = parent;
        this.msgType = msgType;
        setOnLongClickListener(longClickListner);
    }


    public void addViewToCheck(View view)
    {
        this.viewsToCheck.add(view);
    }


    OnLongClickListener longClickListner = new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            if (parent != null && isChecked())
                parent.showTimeDialog(msgType);
            return true;
        }
    };

    OnClickListener listener = new OnClickListener()
    {

        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            if (!isChecked())
            {
                setTextColor(getResources().getColor(R.color.green));
                setPaintFlags(0);
                setChecked(true);
                setCheckMarkDrawable(CHECKED_IMAGE);
                if (parent != null)
                    parent.showTimeDialog(msgType);
            }
            else
            {
                setTextColor(getResources().getColor(R.color.lightgrey));
                setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                setChecked(false);
                setCheckMarkDrawable(UNCHECKED_IMAGE);
            }
            for (View view: viewsToCheck)
                view.setVisibility(isChecked()?View.VISIBLE:View.GONE);
        }
    };

    public CustomCheckBox(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        setOnClickListener(listener);
        System.out.println("1");
        // TODO Auto-generated constructor stub
        // TODO mmmm

    }

    public CustomCheckBox(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        viewsToCheck = new ArrayList<View>();
        String xmlns="http://schemas.android.com/apk/res/ru.human.notification";
        setOnClickListener(listener);       
        System.out.println("2");
        int k = R.drawable.alarmgrey;
        CHECKED_IMAGE = attrs.getAttributeResourceValue(xmlns, "checkedImage", 404);
        UNCHECKED_IMAGE = attrs.getAttributeResourceValue(xmlns, "uncheckedImage", 404);
        setCheckMarkDrawable(UNCHECKED_IMAGE);
        setTextColor(getResources().getColor(R.color.lightgrey));
        setTextSize(18f);
        setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
//      setChecked(false);
        System.out.println(CHECKED_IMAGE +" " + UNCHECKED_IMAGE + " " +k);


        // TODO Auto-generated constructor stub
    }

    public CustomCheckBox(Context context)
    {
        super(context);
        final Context parent = context;
        System.out.println("3");
        // TODO Auto-generated constructor stub
        setOnClickListener(listener);
    }

}
</declare-styleable>


    <declare-styleable name="CustomCheckBox">
        <attr name="uncheckedImage" format="integer"/>
        <attr name="checkedImage" format="integer"/>
    </declare-styleable>

</resources>
<ru.human.notification.CustomCheckBox
                    android:id="@+id/delayed"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/settingsbutton"
                    android:checked="false"
                    customcheckbox:checkedImage="@drawable/clockcolor"
                    android:text="@string/delay"
                    customcheckbox:uncheckedImage="@drawable/clockgrey" />

Put this view to you listview and create setChecked method (code is the same like in onClick method). Don't pay attention on setParent and addViewToCheck method - they are ways to control UI in my app.

Great Suggestion! I rewrote by code to accomodate for this, but I am running into a problem, it seems that on a checkable listview you cannot set the check value from the getView() method. I will look further into this.

You can extend checkedTextView and build in your new view to the listView (check my edition)

Android Search Checkable ListView - Stack Overflow

android listview search
Rectangle 27 0

I solved it by changing the setOnItemClickListener method. The problem was is that I tried to check all the items in my loadFileList() method, which determines all the checkable state, but I should handle single checking and all checking in different parts of code. Now I do it in else statement of setOnItemClickListener...It looks like this:

else
            {

                fileList[myItemInt].toggle(); 
                if(fileList[myItemInt].file.equalsIgnoreCase("select all") & (fileList[myItemInt].check == true))
                {
                    String selectAllFile = fileList[myItemInt].file;
                    File all = new File(path + "/" + selectAllFile);
                     for(int i =0;i<fileList.length;i++)
                        {
                            chosenFile = fileList[i].file;
                            File select = new File(path + "/" + chosenFile);
                             fileList[i].setItemCheck(true);


                             if (select.isFile())
                                 {          
                                     resFiles.add(select);
                                     resFiles.remove(all);

                                 }

                         }

                     adapter.notifyDataSetChanged();
                }

                else if(fileList[myItemInt].file.equalsIgnoreCase("select all") & (fileList[myItemInt].check == false))
                {
                    for(int i =0;i<fileList.length;i++)
                    {

                        fileList[i].setItemCheck(false);

                    }
                     adapter.notifyDataSetChanged();
                }
                if (fileList[myItemInt].check == true)
                    {
                    resFiles.add(sel);
                     if(fileList[myItemInt].file.equalsIgnoreCase("select all"))
                             {
                                String selectAllFile = fileList[myItemInt].file;
                                File all = new File(path + "/" + selectAllFile);
                                resFiles.remove(all);
                             }
                    }
                else
                resFiles.remove(sel);
                adapter.notifyDataSetChanged();
                Log.i(fileList[myItemInt].file,Boolean.toString(fileList[myItemInt].check));
            }   
    }

});

android - Check/Uncheck all the CheckedTextView in a ListView custom a...

android checkbox adapter onclicklistener checkedtextview
Rectangle 27 0

Yes you can do that.On check all click you need to call adapter with values that will tell you need to check all check box in adapter.Similarly with uncheck case. Both time you need to notify adapter to set again value.

alertdialog with listview, check all and uncheck all button android - ...

android listview android-listview android-alertdialog
Rectangle 27 0

One way is to manually uncheck all others radiobuttons. You can create variable that will keep position of currently selected item. And in getView you check/uncheck current radio button depending on whether current position equals to selected one. When use press radio button you change position of selected item and call notifyDatasetChanged. Also check this quesion: Android ListView with RadioButton in singleChoice mode and a custom row layout

private int selected = -1
CitizenAdapter
holder.radioCitizen.setOnClickLisener(new View.OnClickListener() 
    {                              
        @Override
        public void onCheckedChanged(View view) {
            selected = (Integer) view.getTag();
            notifyDataSetChanged();
        }
    });
// After you set text to 4 textviews
holder.radioButCitizen.setTag(position);
holder.radioButCitizen.setChecked(position == selected);

at the accepted answer on that link, there is again some explanation like this, can u specify some code? thanks

Using radio button in custom listview in Android - Stack Overflow

android android-listview radio-button
Rectangle 27 0

do not try to checked and unchecked radioButton pragmatically ...just put that all radio button in one RadioGroup in your XML row layout file.

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="@dimen/marginTen" >

            <RadioGroup
                android:id="@+id/radioGroup1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <RadioButton
                    android:id="@+id/radioButton1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="RadioButton" />

                <RadioButton
                    android:id="@+id/radioButton2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="RadioButton" />

                <RadioButton
                    android:id="@+id/radioButton3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="RadioButton" />
            </RadioGroup>
        </LinearLayout>

They are placed in different layouts in an xml file, may I know how can I make into one radio Group?

please edit your question and put your all xml file.

java - I am unable to uncheck radio buttons in listview - Stack Overfl...

java android eclipse
Rectangle 27 0

You have to do it in your getview() method.

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = null;
    if (convertView == null) {
      LayoutInflater inflator = context.getLayoutInflater();
      view = inflator.inflate(R.layout.yourlayout, null);
      final ViewHolder viewHolder = new ViewHolder();
      viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check);
      viewHolder.checkbox
          .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
              Model element = (Model) viewHolder.checkbox
                  .getTag();
              element.setSelected(buttonView.isChecked());

            }
          });
      view.setTag(viewHolder);
      viewHolder.checkbox.setTag(list.get(position));
    } else {
      view = convertView;
      ((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
    }
    ViewHolder holder = (ViewHolder) view.getTag();
    holder.checkbox.setChecked(list.get(position).isSelected());
    return view;
  }
}

Thnx for your reply :), i am using the same adaptor but how can i set the checkbox values from the main activity?

You just check your checkbox and continue your work. This method will do its work.

i want to check my check box on screen. Instead i want to check the checkbox in the program. I want the checkbox to be checked automatically after a certain condition.

if(position%2==0) viewHolder.checkbox.setChecked(true)

android - Check/Uncheck a checkbox inside a listview, programmatically...

android listview checkbox
Rectangle 27 0

As mentioned above, I just set up a global variable and passed whether I wanted to Select All or Clear All to it. Then I just called my function for populating the ListView. As the ListView is built, it checks the variable in a simple "if" statement, and adds whether to check or uncheck. The cursor adapter then does the check/uncheck as it reruns.

//The code for clearing all.
btnClearAll.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            checkedCount = 0;

            GetMusicMode = "ClearAll";
            GetMusic getMusic = new GetMusic();
            getMusic.execute();
        }       
    });
....
 String track_Title = null;
 String track_Path = null;
 String track_Artist = null;
 String track_Album = null;
 String track_ID = null;
 String track_TrackNumber = null;
 String track_AlbumID = null;
 String track_ArtistID = null;
 String track_Checked = null;

 if (Constants.GetMusicMode.equals("SelectAll")){
track_Checked = "Checked";
}else{
track_Checked = "Not Checked";
 }
 .....

 .....

 HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", track_Title);
song.put("songPath", track_Path);
song.put("songArtist", track_Artist);
song.put("songAlbum", track_Album);
song.put("songTrackNumber", track_TrackNumber);
song.put("songID", track_ID);
song.put("songAlbumID", track_AlbumID);
song.put("songArtistID", track_ArtistID);
song.put("songCheckedStatus", track_Checked);


// Adding each song to SongList
songsList.add(song);

    ....throw to cursor adapter

and finally, this section from the cursoradapter getview

if (songsList.get(position).get("songCheckedStatus").equals("Checked")){
holder.checkTextView.setChecked(true);
}else{
 holder.checkTextView.setChecked(false); 
}

can you share the code of the adapter. i am trying to do the same with a checkbox at the top on the listview. where checking it and unchecking it should check or uncheck all the checkedtextview

listview - Android CheckedTextVIew Clear All/Select All - Stack Overfl...

android listview checkedtextview uncheck
Rectangle 27 0

As per my comment the workflow should be like this : Your Activity :

public class MainActivity extends AppCompatActivity {

private ListView mListView;
private CustomAdapter mCustomAdapter;
private List<YourCustomClass> mYourCustomItems;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    // don't forget to init everything you need
    mYourCustomItems = new ArrayList<>();
    mListView = (ListView) findViewById(R.id.list_view);
    mCustomAdapter = new CustomAdapter(mYourCustomItems);
    mListView.setAdapter(mCustomAdapter);
}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode){
        case  KeyEvent.KEYCODE_BACK:
            //all your needed stuff
            for (YourCustomClass item : mYourCustomItems){
                item.setChecked(false);
            }
            mCustomAdapter.notifyDataSetChanged();
            return true;
    }
    return super.onKeyDown(keyCode, event);
}

private class CustomAdapter extends BaseAdapter{

    private List<YourCustomClass> mYourCustomClasses;

    public CustomAdapter(List<YourCustomClass> yourCustomClasses) {
        mYourCustomClasses = yourCustomClasses;
    }

    @Override
    public int getCount() {
        return mYourCustomClasses.size();
    }

    @Override
    public Object getItem(int position) {
        return mYourCustomClasses.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //all view holder related stuff and other initialization
        CheckBox checkBox = itemView.findViewById(R.id.checkbox);
        checkBox.setChecked(mYourCustomClasses.get(position).isChecked());
        return convertView;
    }
}

listview - Uncheck all checked checkboxes when onBackPressed in androi...

android listview android-checkbox
Rectangle 27 0

I think, you should call invalidate() to each view if you want to update some particular item in ListView. But better approach is to update items through adapter after notifyDataSetChanged() called.

java - I am unable to uncheck radio buttons in listview - Stack Overfl...

java android eclipse
Rectangle 27 0

This is a simple way to uncheck all the children CheckBoxes of a ViewGroup (ListView extends ViewGroup). You'll just want to pass your ListView into this method.

private void uncheckAllChildrenCascade(ViewGroup vg) {
    for (int i = 0; i < vg.getChildCount(); i++) {
        View v = vg.getChildAt(i);
        if (v instanceof CheckBox) {
            ((CheckBox) v).setChecked(false);
        } else if (v instanceof ViewGroup) {
            uncheckAllChildrenCascade((ViewGroup) v);
        }
    }
}

+1 for simple uncheck all checkbox.

uncheck all checbox in listview in android - Stack Overflow

android listview checkbox uncheck