【问题标题】:Show specific row listiview on Android (data from MySQL)在 Android 上显示特定行列表视图(来自 MySQL 的数据)
【发布时间】:2016-06-03 06:43:38
【问题描述】:

在 MySQL 中显示带有数据的 ListView我想转到用户电子邮件所在的特定listivew 行。

电子邮件以前记录在 SQLite 和 MySQL 中。 listview 包括使用不同电子邮件的不同用户。 这是我的代码:

 SimpleAdapter adapter2 = new SimpleAdapter(
            this,list, R.layout.b_server_list_item,
            new String[] { Config.TAG_EMAIL,
                           Config.TAG_ID,
                           Config.TAG_FOTO,
                           Config.TAG_NOMBRE,
                           Config.TAG_PESO,
                           Config.TAG_VASOS,
                           Config.TAG_SEGUIMIENTO},
            new int[] { R.id.list_email,
                        R.id.id,R.id.foto_id,
                        R.id.Nombre,
                        R.id.Peso,
                        R.id.Vasos,
                        R.id.Seguimiento}) {

     @Override
     public View getView (int position, View convertView, ViewGroup parent) {
         View view = super.getView(position, convertView, parent);
         TextView receiverIdTextView = (TextView) view.findViewById(R.id.Rank);
         int pos = position+1;
         receiverIdTextView.setText("" + pos); // This all work OK

         SQLiteDatabase datos;
         datos = getApplicationContext().openOrCreateDatabase("DBMIEMBRO", Context.MODE_PRIVATE, null);
         String query_email = "SELECT * from usermail order by _id DESC limit 1";
         Cursor c_email = datos.rawQuery(query_email, null);
         c_email.moveToFirst();
         // I comproved if it has data. It has an OK display in TextView

         // My problem begins here. I don't know if is the correct way to do what I want
         String listEmail = (c_email.getString(c_email.getColumnIndex(DBhelper.KEY_EMAIL)));
         if (listEmail.equals(R.id.list_email)) {

             listView.setSelection(pos);
         }

         /.../

         return view;
     }

 };

 listView.setAdapter(adapter2);

这不起作用;它显示所有数据,但是这个listview 没有显示用户电子邮件所在的特定行。我想检查存储在 SQLite 中的电子邮件是否在列表中(显示 MySQL),如果是,则显示特定行。

在我检查的代码中,我可以看到我在其中一行(从 MySQL 显示)和textview(从 SQLite 显示)中有相同的邮件。

【问题讨论】:

  • DBhelper.KEY_EMAIL 应该解析为任何列名,我相信它取决于大小写。
  • mysql 与本次讨论完全无关
  • @e4c5 我差点没看。 :)
  • “我妥协了”是什么意思?

标签: php android mysql sqlite listview


【解决方案1】:

下面的检查是完全错误的。您正在使用整数检查字符串值。

if (listEmail.equals(R.id.list_email)) {

    listView.setSelection(pos);
}

取而代之的是,准备一个 mail_id 并检查它。

此外,在 getview 内部实现数据库调用会减慢您的列表视图滚动速度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2012-12-17
    相关资源
    最近更新 更多