データが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());
}
ListAdapterCursor.requery()
をBaseAdapterに変更して、使用できるようにします。notifydatasetchanged()
しかし、何も起こりません..私のリストビューはまだ更新されません
この問題を解決する方法を教えてください