Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there any way to convert
SimpleCursorAdapter to ArrayAdapter


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());
}
Posted

1 solution

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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900