我制作了一个列表视图,数据是从 sqlite 获取的,现在我想让它使用单选按钮按名称或位置排序
这是我的代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
db = new DatabaseHelper(this);
RadioButton rbname = (RadioButton)findViewById(R.id.radio0);
RadioButton rblocation = (RadioButton)findViewById(R.id.radio1);
if (rbname.isChecked()){
Cursor = db
.getReadableDatabase()
.rawQuery("SELECT * FROM " + DatabaseHelper.LIST + " ORDER BY " + DatabaseHelper.NAME, null);
ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, Cursor,
new String[] {DatabaseHelper.NAME, DatabaseHelper.ADDRESS, DatabaseHelper.GENDER, DatabaseHelper.LOCATION},
new int[] {R.id.txtName, R.id.txtAddress, R.id.txtGender, R.id.txtLocation});
setListAdapter(adapter);
}
else if (rblocation.isChecked()){
Cursor = db
.getReadableDatabase()
.rawQuery("SELECT * FROM " + DatabaseHelper.LIST+ " ORDER BY " + DatabaseHelper.LOCATION, null);
ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.row, Cursor,
new String[] {DatabaseHelper.NAME, DatabaseHelper.ADDRESS, DatabaseHelper.GENDER, DatabaseHelper.LOCATION},
new int[] {R.id.txtName, R.id.txtAddress, R.id.txtGender, R.id.txtLocation});
setListAdapter(adapter);
}
registerForContextMenu(getListView());
}
我已经尝试将Cursor.requery()
已经尝试将 ListAdapter 更改为 BaseAdapter 以便我可以使用notifydatasetchanged()
但什么也没发生..我的列表视图仍然没有更新
请帮我解决这个问题