从SQLite的,但有两个字段填入一个Android微调? [英] Populating an Android Spinner from an SQLite but with two fields?

查看:125
本文介绍了从SQLite的,但有两个字段填入一个Android微调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于设法后此code多搞乱但它只能通过一个字段来填充,从一个SQLite数据库一个​​微调,我想第一,在同一个项目微调姓氏?

I've finally managed to populate a spinner from an sqlite db after much messing about with this code however it's only using one field and I want First and Last names on the same spinner item?

在code是如下:

    private void fillSpinner() {
    Cursor c = myDbHelper.FetchDrivers();
    startManagingCursor(c);

    // create an array to specify which fields we want to display
    String[] from = new String[]{"FirstName"};
    // create an array of the display item we want to bind our data to
    int[] to = new int[]{android.R.id.text1};
    // create simple cursor adapter
    SimpleCursorAdapter adapter =
      new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    // get reference to our spinner
    Spinner s = (Spinner) findViewById( R.id.spr_Driver1);
    s.setAdapter(adapter);
}

现在它显示的名字,我已经试过补充说:名字,姓氏,但它并不做任何事情一样,我最好希望它在充分展示各个项目微调的名称。这甚至可能?

Now it displays the FirstName and I've tried added "FirstName", "LastName" but it doesn't do anything different, I ideally want it to display the name in full on each spinner item. Is this even possible?

任何帮助将是巨大的!

谢谢,
克里斯

Thanks, Chris

推荐答案

有关这一点,你需要更改 android.R.layout.simple_spinner_item android.R.layout.simple_spinner_dropdown_item ,因为这些布局的项目都能够在下拉列表和微调,以显示只有一个项目。
你的目的,最好的办法就是创建自己的布局,有两个项目。
<一href=\"http://app-solut.com/blog/2011/03/using-custom-layouts-for-spinner-or-listview-entries-in-android/\"相对=nofollow>这里是一个关于如何做到这一点的链接。

For this, you need to change the android.R.layout.simple_spinner_item and android.R.layout.simple_spinner_dropdown_item, as these layout items are able to display only one item in the dropdown list and on the spinner. For your purpose, the best way is to create your own layout that has two items. Here is a link about how to do it.

这篇关于从SQLite的,但有两个字段填入一个Android微调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆