我在用户注册期间制作了一套带有一系列问题的自助服务表格。
这是string.xml文件
<resources>
sources>
<string name="question1">What was your childhood nickname?</string>
<string name="question2">What is the name of your favorite childhood friend?</string>
<string name="question3">In what city or town did your mother and father meet?</string>
<string name="question4">What is your favorite team?</string>
<string name="question5">What was your favorite sport in high school?</string>
<string name="question6">What was your favorite food as a child?</string>
<string name="question7">What was the make and model of your first car?</string>
<string name="question8">What is you mother\'s maiden name?</string>
<string name="question9">In which city/town were you born?</string>
<string name="question10">In what town/city was your first job?</string>
<string-array name="questions">
<item>Select a question</item>
<item>@string/question1</item>
<item>@string/question2</item>
<item>@string/question3</item>
<item>@string/question4</item>
<item>@string/question5</item>
<item>@string/question6</item>
<item>@string/question7</item>
<item>@string/question8</item>
<item>@string/question9</item>
<item>@string/question10</item>
</string-array>
我已将这些问题提取到活动xml文件中的3个不同的微调器中。
activity_self_service.xml
Spinner spinner1 = (Spinner) findViewById(R.id.spinner_q1);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner_q2);
Spinner spinner3 = (Spinner) findViewById(R.id.spinner_q3);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this, R.array.questions, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.questions, android.R.layout.simple_spinner_item);
ArrayAdapter<CharSequence> adapter3 = ArrayAdapter.createFromResource(this, R.array.questions, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setPrompt("Select a security question");
spinner2.setPrompt("Select a security question");
spinner3.setPrompt("Select a security question");
// Apply the adapter to the spinner
spinner1.setAdapter(adapter1);
spinner2.setAdapter(adapter2);
spinner3.setAdapter(adapter3);
假设用户在3个不同的微调器中选择了问题3,问题5和问题6,我想将这些问题的索引和答案存储在数据库中。
所以,我想要DB中的(3,答案1),(5,答案2),(6,答案3)。
我试图获取索引但无法找到方法。 请帮忙。
答案 0 :(得分:0)
在所有微调器上设置“OnItemSelectedListener”,它会在选择项目时为您提供索引。