我已经在 android ( SQLite ) 中成功创建了一个数据库表。我正在尝试根据名字或姓氏(升序/降序)对数据库中的元素进行排序。(为此,我在上下文菜单中有按钮)。我在编写 SQL 语句时遇到问题。任何想法?
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.database);
ListView lv=(ListView)findViewById(R.id.mylist);
dbh = new DatabaseHelper(this);
c = dbh.getReadableDatabase().rawQuery("SELECT _id, " +
DatabaseHelper.NAME +
", " + DatabaseHelper.LASTNAME +
", " + DatabaseHelper.ans2 +
" FROM " +
DatabaseHelper.TABLE_NAME, null); // initializing
String[] dataFrom ={DatabaseHelper.NAME, DatabaseHelper.LASTNAME, DatabaseHelper.ans2};
int[] dataTo = {R.id.name, R.id.value1, R.id.value2};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.row, c, dataFrom, dataTo);
lv.setAdapter(adapter);
registerForContextMenu(lv);
}