1

我有一个带有复选框的列表,我有两个按钮,保存和清除。单击清除按钮时如何取消选中复选框,

public class myProfileActivity extends Activity {
    private List<Profile> contacts = null;
    private String TAG = "ContactListActivity";
    private String inputName;
    ListView lvContact;
    private Activity _activity;

    private ListView mainListView;
    private Profile[] itemss;
    private ArrayAdapter<Profile> listAdapter;
    ArrayList<String> checked = new ArrayList<String>();
    public static List<AttractionData> selectedData = new ArrayList<AttractionData>();
    private String profileType = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        ContentResolver cr = this.getContentResolver();
        setContentView(R.layout.profilelist);
        _activity = this;

        profileType = getIntent().getExtras().getString("ProfileType");

        try {
            if (Constants.loadEntries != null) {
                Constants.loadEntries.cancel(true);
            }
        } catch (Exception e) {
            Log.e(TAG, "Loading Data------", e);
        }
        Constants.loadEntries = new LoadEntries();
        Constants.loadEntries.execute();
        EditText editTxt = (EditText) findViewById(R.id.txtContName);

        editTxt.addTextChangedListener(new TextWatcher() {

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            public void afterTextChanged(Editable s) {
                inputName = s.toString();
                Log.d(TAG, "LoadMoreEntries --> Constants.loadEntries : "
                        + Constants.loadEntries);
                try {
                    if (Constants.loadEntries != null) {
                        Constants.loadEntries.cancel(true);
                    }
                } catch (Exception e) {
                    Log.e(TAG, "Loading Data--------", e);
                }
                Constants.loadEntries = new LoadEntries();
                Constants.loadEntries.execute();
            }

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            }
        });


        Button clearbtn = (Button) findViewById(R.id.clearbtn);
        clearbtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {


        }
        });



        Button savebtn = (Button) findViewById(R.id.savebtn);
        savebtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (Constants.selectedContacts.size() > 0) {
                    ((CityPreferences) ProfileActivity.this.getApplication())
                            .storeAllContacts(Constants.selectedContacts);
                    Constants.selectedContacts= new ArrayList<Profile>();
                    finish();
                    v.getContext().startActivity(
                            new Intent(v.getContext(), PalABActivity.class)
                                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));


                } 
            });


    }

任何帮助表示赞赏。

4

5 回答 5

2

在按钮的 onclick 监听器中

添加

    chkBOX.setChecked(false);
于 2013-01-03T10:33:54.533 回答
1
final CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox_id);
checkBox.setChecked(false);

编辑:

View v;
final CheckBox checkBox = (CheckBox) v.findViewById(R.id.checkbox_id);

view v你的膨胀视图在哪里

于 2013-01-03T10:31:44.407 回答
1

这对我有用

 Button clearbtn1 = (Button) findViewById(R.id.clearbtn);
        clearbtn1.setOnClickListener(new OnClickListener() {
            @Override

            public void onClick(View v) {
              for(int i=0;i < Constants.checkBoxState.length; i++)      
                 Constants.checkBoxState[i] = false;

              listAdapter.notifyDataSetChanged();

        }
        });
于 2013-01-04T07:19:29.003 回答
0

膨胀(findViewById)您要编辑的复选框,然后调用

myCheckbox.setChecked(false);
于 2013-01-03T10:31:51.467 回答
0

像这样创建一个类。

    public class MyApplication extends Application{

       private int check_state = 1;

        public void setState(int state)
           {
         check_state = state;
           }
        public int getState()
           {
          return check_state;
           }

      }

在您的活动中

要设置复选框状态的位置

        ((MyApplication)getApplication()).setState(0);

要获取复选框状态的位置

        ((MyApplication)getApplication()).getState();

在清单文件中

    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:name=".MyApplication">
于 2013-01-03T11:02:16.527 回答