当我选择“优先级”单选按钮(id=radioButton)通过查看评级进行排序时,应用程序自行关闭。当我删除 RadioGroup.OnCheckedChangeListener() { @Override 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);
}
}
我猜R.id.radioButton
是被点击的 RadioButton 的 id 吗?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句