我想获得在我的活动中运行的 4 个微调器中选择的位置的 int 值。一旦我有了 Int 值,我想根据这个值循环并将一个文件写入 SDCARD,选择 IE spinner1 item 4,在 sdcard 上生成文本文件 1、2、3、4。
我不确定如何获取用户在每个微调器中单击的位置的 int 值,但我想在选择图像按钮时“收集”这些值,目前这是我的代码;
//used to track spinner value
public int spinner1 = 0;
public int spinner2 = 0;
public int spinner3 = 0;
public int spinner4 = 0;
etnumber1 = (Spinner) findViewById(R.id.etnumber1);
etnumber2 = (Spinner) findViewById(R.id.etnumber2);
etnumber3 = (Spinner) findViewById(R.id.etnumber3);
etnumber4 = (Spinner) findViewById(R.id.etnumber4);
etnumber1.setOnItemSelectedListener(this);
etnumber2.setOnItemSelectedListener(this);
etnumber3.setOnItemSelectedListener(this);
etnumber4.setOnItemSelectedListener(this);
}//end of oncreate
public void onClick(View v) {
if (v==imagerun) {
for (int i=1; i<spinner1; i++){
//primary callsign
Toast.makeText(getBaseContext(), String.valueOf(i),
Toast.LENGTH_SHORT).show();
String fileName = String.valueOf(i) +".txt";
File myFile = new File("/sdcard/.working/" +fileName);
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile, false);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(etpri1.getText());
myOutWriter.append(" ");
myOutWriter.append(String.valueOf(i));
myOutWriter.close();
fOut.close();
}
}
catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}//end onclick
public void onItemSelected(AdapterView<?> parent, View view1, int pos,
long id) {
// TODO Auto-generated method stub
spinner1=etnumber1.getSelectedItemPosition(); // primary number
spinner2=etnumber2.getSelectedItemPosition(); //secondary
spinner3=etnumber3.getSelectedItemPosition(); //primary number
spinner4=etnumber4.getSelectedItemPosition(); //secondary number
}
我显然做错了,我尝试遵循很多教程,但它们都指的是从单个微调器获取字符串值。抱歉,这可能是一个简单的请求,但我整天都在为此努力!
谢谢你的帮助。