如何在列表视图中隐藏未选中的单选按钮?

时间:2019-02-26 12:10:43

标签: android listview radio-button

我想在列表视图中隐藏或禁用未选中的单选按钮... 我是这样的:

if (!radioButton.isChecked()){
                    radioButton.setVisibility(View.GONE);
}

但是它不起作用..现在我不知道该怎么做。...

  

代码:

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater= (LayoutInflater) votingForCVc.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView=layoutInflater.inflate(R.layout.cvcitemfile,parent,false);
        final TextView checkedTextView = convertView.findViewById(R.id.itemvoting);
        final RadioGroup radioGroup=convertView.findViewById(R.id.rdgrp);
        checkedTextView.setText(playernmae.get(position));
        final View finalConvertView = convertView;
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radioButton = finalConvertView.findViewById(R.id.rdbtn);
                Integer v = null;
                Integer v1 = null;
                if (radioButton.isChecked()) {
                    for (int i = 0; i < player_id.size(); i++) {
                        v1= Integer.valueOf(player_id.get(position));
                        v = Integer.valueOf(vote1.get(position));
                        v += 1;
                    }
                    Toast.makeText(votingForCVc, "Thanks For Voting.", Toast.LENGTH_SHORT).show();
                }
  return convertView;
    }
}

1 个答案:

答案 0 :(得分:0)

实际上,您需要持有人,您可以得到一些答案。如果您使用recyclerview,则将解决此问题。 RecyclerView vs. ListView