Click here to Skip to main content
13,087,566 members (82,603 online)
Rate this:
 
Please Sign up or sign in to vote.
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 31-Dec-12 18:37pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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>
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100