如何在 vigiltime.setText 中显示对象的另一个字段?我希望它显示来自 parishArrayList 的对象的时间字段的特定相关值?parent.getItemAtPosition(position) 已经检索到特定对象,那么我怎样才能让它解析 onItemSelected 方法中的相关对象详细信息?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parishArrayList = new ArrayList<>();
parishArrayList.add(new Parish(1, "Aghyaran", "Termonamongan, N.West Tyrone", "6.30pm", "10.00am"));
parishArrayList.add(new Parish(2, "Castlederg", "Castlederg, N.West Tyrone", "7pm", "11.00am"));
parishArrayList.add(new Parish(3, "Strabane", "Strabane, N.West Tyrone", "8pm", "12.00am"));
Spinner parishSpinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the parishArrayList and a default spinner layout
ArrayAdapter<Parish> parishAdapter = new ArrayAdapter<Parish>(getApplicationContext(), android.R.layout.simple_spinner_item, parishArrayList);
// Specify the layout to use when the list of choices appears
parishAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
parishSpinner.setAdapter(parishAdapter);
parishSpinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView vigiltime = (TextView) findViewById(R.id.vigiltime);
vigiltime.setText("Spinner selected : ");
vigiltime.setText(vigiltime.getText() + parent.getItemAtPosition(position).toString());
}
慕标琳琳
jeck猫
动漫人物
相关分类