我有一个使用edittexts和spinners的活动。我在每个中设置值,然后将它们保存在数据库中。现在在具有完全相同的xml文件的第二个活动中,我想使用db中的值自动填充它们以便修改它们。我使用.setText来填充edittexts,它工作正常。我可以用什么来填充旋转器?
示例代码如下......
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.
}
}
答案 0 :(得分:0)
将您的商品加载到数组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