andro-girl
andro-girl

Reputation: 8129

hiding the checkbox of checkedtextview

i m using checkedtextview in listview.i want to display olly the textview when d list view is first loaded.when i click on a button i want to populate the list view with different data and which should show the checkbox also.(i m not able to hide the checkbox of checked textview initially).plz help me

Upvotes: 6

Views: 4707

Answers (3)

Fay Zan
Fay Zan

Reputation: 165

This question is old, but this might help someone in the future

Step 1

create a boolean variable in onCreate to ease the if|else|while method (will use in step 3)

 boolean changedData = true;

Step 2

i want to display olly the textview when d list view is first loaded

Just leave your code as it is, assuming it looks like this

ArrayAdapter<String> adapter
                        = new ArrayAdapter<String>(yourActivity.this,
                        android.R.layout.simple_list_item_1,
                        yourData);
listView.setAdapter(adapter);

Step 3

when i click on a button i want to populate the list view with different data and which should show the checkbox also

just create a new button like so

 populateBtn.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v) {
        if (changedData == true) {
            ArrayAdapter<String> adapter 
                                    = new ArrayAdapter<String>(yourActivity.this,
                                    android.R.layout.simple_list_item_multiple_choice,
                                    differentData);
           listView.setAdapter(adapter);
           changedData = false;
        }else if (changedData == false) {
                 ArrayAdapter<String> adapter 
                                    = new ArrayAdapter<String>(yourActivity.this,
                                    android.R.layout.simple_list_item_1,
                                    yourData);
           listView.setAdapter(adapter);
           changedData = true;
        }
   });
}

This way, the first time you click your button you will get a ListView with CheckBox with your new data

And upon clicking the button again it will go back to the ListView with no CheckBox with your old data

If you want to make the CheckBox checkable, just read the answer from this link

Simple list item multiple choice not selecting items

Upvotes: 0

Matthew Carpenter
Matthew Carpenter

Reputation: 660

<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:checkMark="@null"/>

Upvotes: 0

Vincent Mimoun-Prat
Vincent Mimoun-Prat

Reputation: 28551

I would simply use a custom adapter that will return either a TextView or a CheckedTextView depending on whether you have clicked your button.

Also you could try to do checkedTextView.setCheckMarkDrawable(null);

Upvotes: 6

Related Questions