#android
#Android
Вопрос:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Model model = new Model("1","GYM");
Model model1 = new Model("2","Football");
Model model2 = new Model("3","Cricket");
Model model3 = new Model("4","VolleyBall");
//Getting the instance of Spinner and applying OnItemSelectedListener on it
spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
//Creating the ArrayAdapter instance having the country list
// Creating adapter for spinner
ArrayList<Model> arraylist = new ArrayList<Model>(); // This is actually the list created from the HashMap
arraylist.add(model);
arraylist.add(model1);
arraylist.add(model2);
ArrayAdapter<Model> adapter = new ArrayAdapter<Model>(this, android.R.layout.simple_spinner_item, arraylist);
spin.setAdapter(adapter);
//Setting the ArrayAdapter data on the Spinner
Model selectedItem = (Model) spin.getSelectedItem(); // Object which was selected.
selectedItem.getService_iD(); // This will give you the ID of the item selected. Do whatever you wish with to do.
Log.e("asdfgg", "onCreate: " selectedItem.getService_iD());
Log.e("TAG", "onCreate: " model.getService_iD());
}
//Performing action onItemSelected and onNothing selected
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
Model selectedItem = (Model) spin.getSelectedItem(); // Object which was selected.
selectedItem.getService_iD(); // Th
Log.e("fdfda", "onItemSelected: " selectedItem.getService_iD() );
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
Комментарии:
1. В чем вопрос?
2. Я показываю данные (Service_Name) 2-го индекса моих объектов ArrayList при открытии счетчика, но я хочу получить (в logcat) ArrayList отображает данные в первом индексе (Service_Id), соответствующем тому, какой элемент нажимается на счетчик, когда я нажимаю на элементы счетчика