为什么radiobutton不能使用此代码?

问题描述 投票:0回答:1

当我通过查看评级选择“priority”radiobutton(id = radioButton)进行排序时,应用程序自行关闭。当我删除RadioGroup.OnCheckedChangeListener(){@ Overver public void onCheckedChanged(RadioGroup group,int checkedId){rb.findViewById(checkedId) ); if(rb == rb1){Collections.sort(phonelist); }}};这部分它除了排序以外工作正常。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);




    attachViews();
    this.initializeViews();




    /*RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);
    phoneAdapter = new PhoneAdapter(this, phonelist);
    recyclerView.setAdapter(phoneAdapter);*/

    updateTotal();










}

public void sortData(boolean asc) {
    //SORT ARRAY ASCENDING AND DESCENDING
    if (asc) {
        Collections.sort(phonelist);
    } else {
        Collections.reverse(phonelist);
    }
}


private void initializeViews()
{
    rg=findViewById(R.id.radiogroup1);
    rb1=findViewById(R.id.radioButton);
    rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            rb.findViewById(checkedId);
            if(rb==rb1){
                Collections.sort(phonelist);
            }
        }
    });


    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
    recyclerView= (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));

    phoneAdapter = new PhoneAdapter(this, phonelist);
    recyclerView.setAdapter(phoneAdapter);
java android
1个回答
0
投票

将侦听器更改为:

public void onCheckedChanged(RadioGroup group, int checkedId) {
    if(checkedId == R.id.radioButton){
        Collections.sort(phonelist);
    }
}

我想qazxsw poi是单击的单选按钮的ID?

© www.soinside.com 2019 - 2024. All rights reserved.