安卓sqlite中cursor问题,点击查询没有反应,怎么将查询的学号信息从数据库中显示在下面的三个EditText上 20
点击查询没有反应,怎么将查询的学号信息从数据库中显示在下面的三个EditText上(学号,姓名,宿舍号)?这是我的代码:publicclassthirdActivitye...
点击查询没有反应,怎么将查询的学号信息从数据库中显示在下面的三个EditText上(学号,姓名,宿舍号)?这是我的代码:public class thirdActivity extends Activity { EditText t1,t2,t3,t4; Button b1,b2; SQLiteDatabase db; Cursor cursor; public int id_this; static String TABLE_NAME="Users"; static String ID="_id"; static String USER_NAME="user_name"; static String NUM="num"; static String SNO="sno"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hey); t1=(EditText)findViewById(R.id.editText3); t2=(EditText)findViewById(R.id.editText20); t3=(EditText)findViewById(R.id.editText21); t4=(EditText)findViewById(R.id.editText22); b1=(Button)findViewById(R.id.button3); b1.setOnClickListener(new mClick()); b2=(Button)findViewById(R.id.button20); b2.setOnClickListener(new mClick1()); }class mClick implements OnClickListener{@Override public void onClick(View v){ db=openOrCreateDatabase("sql.db", SQLiteDatabase.CREATE_IF_NECESSARY,null); try { db.execSQL("create table if not exists "+TABLE_NAME+ " (ID integer primary key autoincrement, " + "USER_NAME text not null,NUM text not null, SNO text not null);"); } catch (SQLException e) { Toast.makeText(getApplicationContext(), "数据表创建失败", Toast.LENGTH_LONG).show(); } ContentValues values = new ContentValues(); values.put(USER_NAME,"1" ); values.put(SNO,"1" ); values.put(NUM,"1" ); db.insert(TABLE_NAME, null, values); String[] columns = new String[] { "ID", "USER_NAME", "NUM","SNO" }; String selection = "ID=?"; String[] selectionArgs = { String.valueOf(ID) }; String groupBy = null; String having = null; String orderBy = null; cursor= db.query(TABLE_NAME, columns, selection, selectionArgs, groupBy, having, orderBy); } }
展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询