开发者

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


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);


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜