スピナーの文字列名を前のスピナー選択項目から動的にアンドロイドに変更したい。スピナーの文字列名を前のスピナー選択項目から動的に変更
これは私のActivityクラスです:
public class SelectionActivity extends AppCompatActivity implements View.OnClickListener {
final String LOG = "Selection";
private Spinner spBranch;
private Spinner spSection;
private Spinner spSemester,spSubject;
private Button btnSend;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selection);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
spBranch = (Spinner) findViewById(R.id.spBranch1);
spSection = (Spinner) findViewById(R.id.spSection1);
spSemester = (Spinner) findViewById(R.id.spSemester1);
spSubject=(Spinner) findViewById(R.id.spSubject1);
String[] items1 = new String[]{"CSE", "EEE", "EE", "ECE", "MECH", "CIVIL"};
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items1);
spBranch.setAdapter(adapter1);
String[] items2 = new String[]{"A", "B", "C", "D", "E", "F"};
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items2);
spSection.setAdapter(adapter2);
String[] items3 = new String[]{"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th"};
ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items3);
spSemester.setAdapter(adapter3);
String[] items4 = new String[]{"Math 1", "Programming in C", "Thermodynamics", "Communication English", "Physics", "Basic Electronics"};
String[] items5 = new String[]{"Chemistry", "Data Structure", "Mechanics", "Buiseness English", "Basic Electrical Engineering l ", "Math 2"};
if(spSemester.getSelectedItem().toString().equals("1st"))
{
ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,items4);
spSubject.setAdapter(adapter4);
}
else{
ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,items5);
spSubject.setAdapter(adapter4);
}
btnSend = (Button) findViewById(R.id.btnSend);
}
@Override
public void onClick(View v) {
Intent in = new Intent(SelectionActivity.this, ListActivity.class);
startActivity(in);
HashMap postData = new HashMap();
postData.put("txtBranch", spBranch.getSelectedItem().toString());
postData.put("txtSection", spSection.getSelectedItem().toString());
postData.put("txtSemester", spSemester.getSelectedItem().toString());
}
}
私は新andoridするspSubject.setAdapter(adapter4);
このラインRでエラーを取得していますので、この
正確なエラーは何ですか? –
'items1'、' items2'などよりもわかりやすい名前を使うことをお勧めします。たとえば、 'items1'は' strBranch'です。 –