当我通过查看评级选择“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);
将侦听器更改为:
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.radioButton){
Collections.sort(phonelist);
}
}
我想qazxsw poi是单击的单选按钮的ID?