qq_34304603 2016-12-22 13:56 采纳率: 0%
浏览 835

初学者安卓设计 这个问题很困惑 我想把这数据库里表里所有信息显示出来

但每次只能显示最后一次登录的名字代码 请问怎么改

public class student extends Activity {

MyDatabaseHelper database;
TextView tv_name,tv_age,tv_sex;


@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.student);
    tv_name=(TextView)findViewById(R.id.tv_name);
    tv_age=(TextView)findViewById(R.id.tv_age);
    tv_sex=(TextView)findViewById(R.id.tv_sex);

    database=new MyDatabaseHelper(this,"RE.db",null, 1);
    SQLiteDatabase db=database.getWritableDatabase();


    Cursor cursor = db.query("student", null, null, null, null, null, null); 
    if (cursor != null) {
    while (cursor.moveToNext()) { 


        String name = cursor.getString(cursor.getColumnIndex("username")); 
        String age = cursor.getString(cursor.getColumnIndex("age"));
        String sex=cursor.getString(cursor.getColumnIndex("sex"));
        String id=cursor.getString(cursor.getColumnIndex("id"));
        tv_name.setText(name.toString());
        tv_sex.setText(sex.toString());
        tv_age.setText(age.toString());


        }
    cursor.close();

}
}

        }
  • 写回答

4条回答 默认 最新

  • qq_34304603 2016-12-22 14:36
    关注

    AAAAAAAAAAAAAAA

    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办