【发布时间】:2015-08-22 11:43:41
【问题描述】:
我正在尝试将从微调器中选择的值传递给另一个类,但它传递了 null。
protected int secondsToUse;
final String titles[] = {
"1 Second","2 Seconds", "3 Seconds","4 Seconds",
"5 Seconds","6 Seconds","7 Seconds","8 Seconds","9 Seconds","10 Seconds"
};
mSeconds = (Spinner) view.findViewById(R.id.secondsSpinner);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, titles);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSeconds.setAdapter(arrayAdapter);
mSeconds.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// secondsToUse is declared a as int variable above
secondsToUse = position + 1;
}
// passing the value to another class.// PASSES AS NULL
Intent recipientsIntent = new Intent(getActivity(), RecipientsActivity.class);
recipientsIntent.putExtra("key1", secondsToUse);
startActivity(recipientsIntent);
// retrieving the value //retrieves as null
String Seconds = getIntent().getStringExtra("key1");
byte[] secs = Seconds.getBytes();
我正在尝试获取用户在微调器上选择的位置,以便我可以将其传递给计时器以使图像自毁。此刻我为空
【问题讨论】:
-
将 secondsToUse 设为静态
标签: javascript android arrays android-intent android-spinner