我有一个Spinner我填充了ArrayAdapter对象,但是我需要这个Array的第一个位置始终为null或者出现类似"选择一个对象"。我在这里搜索了论坛,但没有成功,没有成功的ArrayList String或spinner.setPrompt的解决方案= /
ArrayList<Object> objects = null;
objects= findMyObjects();
final ArrayAdapter<Object> adapterObjects = new ArrayAdapter<Object>(contexto, R.layout.spinner_item, objects);
mySpinner = (Spinner) viewPai.findViewById(R.id.s_spinner);
mySpinner.setAdapter(adapterObjects);
adapterObjects.notifyDataSetChanged();
mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
public ArrayList<Object> findMyObjects() {
allObjects = new ArrayList<Object>();
Cursor cursor;
String sql = "SELECT * FROM Object; ";
cursor = database.rawQuery(sql, null);
if (cursor.getCount() >= 0) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Objects object = new Objects();
object.setId(cursor.getLong(0));
allObjects.add(object);
cursor.moveToNext();
}
}
cursor.close();
return allObjects;
}
答案 0 :(得分:2)
答案 1 :(得分:0)
制作一个虚拟对象,然后放入适配器显示=&#34;选择一个对象&#34;
扩展arrayadapter或放置值的视图,以便第一个对象始终是一个文字说&#34;选择一个对象&#34;。