我想把我的getText的scrapBookId放在textview上,我能够干杯并返回值,但是一旦我把它放到textview中就没有价值,有人可以帮我吗?谢谢
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.upload);
addListenerOnButton();
userid = (TextView) findViewById(R.id.userid);
spinner = (Spinner) findViewById(R.id.spinnerscrapbookid);
sbid = (TextView)findViewById(R.id.scrapbook_id);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// ---getting values from selected Spinner
scrapBookId = ((TextView) view.findViewById(R.id.scrapBookId)).getText().toString();
Toast.makeText(getApplicationContext(), "" + scrapBookId, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
sbid.setText(scrapBookId);
//---HashMap for SpinnerView
scrapBookList = new ArrayList<HashMap<String, String>>();
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(this);
userid.setText(sp.getString("user_id", null));
imageview = (ImageView) findViewById(R.id.imageView);
new LoadAllScrapBook().execute();
}
答案 0 :(得分:1)
您还必须将该行放入OnItemSelectedListener
:
sbid.setText(scrapBookId);
正如您现在所做的那样,您在用户选择了任何内容之前在TextView
中显示了ID,因此您当然会看到您初始化的值scrapBooxId
用。