【问题标题】:Listview with radiobutton from server带有来自服务器的单选按钮的列表视图
【发布时间】:2015-05-02 17:24:22
【问题描述】:

我正在使用this 教程。我有一个带有单选按钮的列表视图。当我单击列表视图值时,所有单选按钮都会更改检查。我想要单选模式并在单击提交按钮时检查单选按钮列表值。 这是我的 onpostexecute

  protected void onPostExecute(JSONObject file_url) {
            // dismiss the dialog after getting all albums
            Log.d("Arraylist: ", "> " + AddressList);

            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                   if(!AddressList.isEmpty())
                   {
                final ListAdapter adapterlist = new SimpleAdapter(
                            PlaceEnquiryActivity.this, AddressList,
                            R.layout.addressscreenlist, new String[] { ADDRESS,
                                    CITY, STATE, COUNTRY }, new int[] {R.id.address,
                                    R.id.city, R.id.state, R.id.country});

                    // updating listview
                    setListAdapter(adapterlist);

这是activity中的listview onclick函数

  final ListView lv = getListView();
        lv.setItemsCanFocus(false);
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
            RadioButton rb = (RadioButton) v.findViewById(R.id.rb_Choice);
            if (!rb.isChecked()) //OFF->ON
            {
            for (HashMap<String, String> m:AddressList) //clean previous selected

                rb.setChecked(true);
            //lv.getAdapter().notifyDatasetChanged();
            }
            }        
            });

【问题讨论】:

    标签: android listview android-listview radio-button


    【解决方案1】:

    你犯错了 for (HashMap m:AddressList) //清除之前选中的

                rb.setChecked(true);
            //lv.getAdapter().notifyDatasetChanged();
            }
    

    使用条件用于已检查和未检查。如果未检查,则使其检查。不要将 for 循环用于 setchecked(true)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 2016-02-03
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多