誰でも私を助けることができますか?
spinner2 は、Toast (コードの下) を使用して表示する必要がある選択された位置を表示しません。
コードの問題点が見つかりません。あなたの応答は非常に高く評価されています。ありがとうございました。
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5.67"
android:entries="@array/groupLamp />
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*parameters*/
final Integer incandescant[]={5,15,25,35,40,60,75,100,125,150};
final Integer led[] = {0,2,3,5,8,13,15,20,23,28};
final Integer cfl[] = {0,0,0,0,13,15,25,30,40,45};
final Integer fluorescent[] = {40,40,20,55};
Button btnCalc = (Button) findViewById(R.id.btnCalculate);
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
final Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
List<String> list = new ArrayList<String>();
list.add("Incandescant");
list.add("CFL");
list.add("Flourescent");
list.add("Others");
final List<String> list2 = new ArrayList<String>();
final List<String> list3 = new ArrayList<String>();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
list2.clear();
if(pos==0){
for(Integer ctr: incandescant){
list2.add(ctr+ " watts");
}
}else if(pos==1){
for(Integer ctr: led){
list2.add(ctr +" watts");
}
}
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list2);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(dataAdapter2);
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Toast.makeText(MainActivity.this, ""+pos, Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}