Android:将SimpleCursorAdapter转换为ArrayAdapter [英] Android : Convert SimpleCursorAdapter to ArrayAdapter
本文介绍了Android:将SimpleCursorAdapter转换为ArrayAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将
SimpleCursorAdapter to ArrayAdapter
我在微调器中绑定数据当我想得到微调器的文本,
我得光标id,
这是我在spinner中获取数据和绑定的代码< br $> b $ b
I am binding data in spinner and when I want to get the text of spinner ,
I am getting cursor id ,
this is my code to get data and binding in spinner
subSpin = (Spinner) findViewById(R.id.spinner1);
try {
cursor = dbHelper.getSpinnerData();
startManagingCursor(cursor);
String[] from = new String[] { DatabaseHelper.sub_id,
DatabaseHelper.sub_name };
int[] to = new int[] { 0, android.R.id.text1 };
SimpleCursorAdapter subAdapter = new SimpleCursorAdapter(
AddResultScreen.this, android.R.layout.simple_list_item_1,cursor, from, to);
subAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
subSpin.setAdapter(subAdapter);
subSpin.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> selectedItem,
View arg1, int pos, long arg3) {
// TODO Auto-generated method stub
subjectName = subSpin.getSelectedItem().toString();
System.out.println(subjectName);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
} catch (Exception e) {
// TODO: handle exception
System.out.println(e.toString());
}
推荐答案
我自己解决了这个问题,
不要在光标中获取数据但在列表中获取数据
当你从sqlite数据库获取数据时,
将光标绑定在List
中,你可以这样做
I solved my self this ,
Don''t get data in cursor but get data in List
there is when you are getting data from sqlite database ,
Bind cursor in List
like this you can do
List<string> labels = new ArrayList<string>;
String addData = cursot.getString(cursor.getColumnIndex("ColumnName"));
labels.add(addData);</string></string>
这篇关于Android:将SimpleCursorAdapter转换为ArrayAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文