【发布时间】:2015-04-04 15:16:57
【问题描述】:
我已将列中的内容放入微调器中。这是我使用复选框数组(稀疏布尔数组)保存内容的列,因此这意味着它有许多用“,”分隔的单词。我设法在微调器中显示内容,但所有内容都在一行中,而不是每个单词都在自己的行中并带有逗号。这是我用来显示光标微调器的代码
Cursor cursor = dbHelper.getAllRows();
if(cursor.getCount()>0){
String[] from = new String[]{"Facilities"};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item,
cursor, from, to);
mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spFacilityType.setAdapter(mAdapter);
}
spFacilityType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView parent, View view,
int pos, long log) {
Cursor c = (Cursor)parent.getItemAtPosition(position);
int id = c.getInt(c.getColumnIndexOrThrow("Facilities"));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
维克托。这是 getAllRows() 的代码
public Cursor getAllRows() {
String where = null;
Cursor c = db.query(true, DATABASE_TABLE, ALL_KEYS,
where, null, null, null, KEY_STATION_NAME, null);
if (c != null) {
c.moveToFirst();
}
return c;
}
Kyus 上瘾。这是我尝试过的。但是应用程序崩溃了
Cursor cursor = dbHelper.getAllRows();
TextUtils.SimpleStringSplitter simpleStringSplitter=new TextUtils.SimpleStringSplitter(',');
List<String> lables = (List<String>) dbHelper.getAllRows();
if(cursor.getCount()>0) {
String[] from = new String[]{"Facilities"};
// create an array of the display item we want to bind our data to
int[] to = new int[]{android.R.id.text1};
ArrayAdapter<String> adapter =
new ArrayAdapter<>(AddReview.this, // This is your context
android.R.layout.simple_dropdown_item_1line, // This is your layout
lables); // This is your data
spFacilityType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
int index = arg0.getSelectedItemPosition();
position = index;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
【问题讨论】:
-
添加dbHelper.getAllRows()的代码;