【问题标题】:Populate spinner from database with previous values使用以前的值从数据库中填充微调器
【发布时间】:2013-03-21 23:51:23
【问题描述】:

我有一个关于编辑文本和微调器的活动。我在每个中设置值,然后将它们保存在数据库中。现在在具有完全相同的 xml 文件的第二个活动中,我想用数据库中的值自动填充它们,以便修改它们。我使用 .setText 来填充编辑文本,它工作正常。我可以用什么来填充微调器??

示例代码如下...

package com.alex.example;
import ...

public class Profile extends Activity {

    DatabaseHelperUser db = new DatabaseHelperUser(this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);
        final EditText edtName = (EditText) findViewById(R.id.edtName);
        final Spinner spnSex = (Spinner) findViewById(R.id.spnSex);
        final ImageButton btnConfirm = (ImageButton) findViewById(R.id.btnChickListed);

        Bundle b = getIntent().getExtras();
        final int userid = b.getInt("id");
        final User user = db.getUser(userkid);

        edtName.setText(user.get_name());
        spnSex.
}
}

【问题讨论】:

    标签: android database android-spinner


    【解决方案1】:

    将您的项目加载到数组中array_spinner 那么:

    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, array_spinner);
    spnSex.setAdapter(adapter);
    spnSex.setSelection(value); // if you want to select a value that you stored somewhere
    

    【讨论】:

    • 除了我设置用户时选择的值之外,数据库中没有任何微调器值。我怎样才能把它们都放在数组中?对不起,如果这个问题看起来很愚蠢,但我是 android 的新手。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多