public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select);  
        final Button button_select=(Button)findViewById(R.id.button2);
        button_select.setOnClickListener(new View.OnClickListener() {
 
    /*************************单击按钮查询数据开始**************************/
         public void onClick(View v) {
 
       database temp = new database(select.this, "database_sage");
           SQLiteDatabase db = temp.getWritableDatabase();
  Cursor cursor = db.query("user", new String[]{"name", "phone","address"}, null, null, null, null, null);
        while(cursor.moveToNext())  {
       ?? ??????? } 
  }
  });
     /*********************************单击按钮查询数据结束*************************/  我初学,想问一下在问号处用什么样的代码可以得到我想要的功能
1.遍历出数据库中的全部数据显示在屏幕上
2.当在画面出点击其中一条记录时可以跳到新的activity画面
麻烦高手帮说的详细些,呵呵谢谢
 

解决方案 »

  1.   

    1.遍历出数据库中的全部数据显示在屏幕上
    private List<HashMap<String, String>> List; 
    while (cursor.moveToNext()) {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("_id", cursor.getString(cursor.getColumnIndex("_id")));

    Car_List.add(map);
    }
    在吧list绑定到listview上
    2.当在画面出点击其中一条记录时可以跳到新的activity画面
    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    System.out.println(position);
    Intent intent = new Intent(xxx,xxx);
                    startActivity(intent);
    }
      

  2.   

    那如果在点击listview里其中一条记录,并获得该记录的字段的数据应该在onListItemClick方法中怎么写呢
    比如说我表里总共有2个字段,name,password那当我点击listview里其中一条数据怎样获得该记录name和password字段所对应的值呢。
      

  3.   

    protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    System.out.println(position);
    String name = List.get(position).get("name").tostring(); 
    ....
    Intent intent = new Intent(xxx,xxx);
      startActivity(intent);
    }
      

  4.   

    2楼的方法有点问题, 人家是要得到全部的数据,还有最起码的,对cousor.moveToNext() 的操作必须用do..while  ,不然就漏掉第一个 ,最好在遍历前调用一下 cousor.moveToFirst() 判断一下。