I am trying to create an app to enter records into a database (SQLite) which includes an option field with data selected from a drop-down list box or Spinner. I can create the Spinner from a string array input from Strings.xml but I want to make the data 'user editable,' but cannot find a way to create it. The latest effort below stops after reporting it is switching to the database (at the declaration and initialisation of 'colurs.')
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mDbHelper = new NamesDbAdapter(this);
mDbHelper.open();
Log.d("onCreate", "Creating Edit screen");
setContentView(R.layout.names_edit);
mConfirmButton = (Button) findViewById(R.id.confirm);
mPremier = (EditText) findViewById(R.id.premier);
mDenier = (EditText) findViewById(R.id.denier);
mDetail = (EditText) findViewById(R.id.detail);
mOptid = (Spinner) findViewById(R.id.spinner);
Log.d("Edit recd","Reading options table");
Cursor pallette=mDbHelper.readOptionsTable();
startManagingCursor(pallette);
Log.d("Edit recd","Setup spinner");
//String[] mOptions;
//String[] from = new String[] {NamesDbAdapter.KEY_OPTION};
//Log.d("Loaded",from[0]);
//int[] to = new int[] {R.id.text1};
Log.d("Edit rec","Create adapter");
//SimpleCursorAdapter picklist = new SimpleCursorAdapter(this,R.layout.names_row, pallette, from, to);
ArrayAdapter<CharSequence> picklist = ArrayAdapter.createFromResource(this, R.array.choisir2, android.R.layout.simple_spinner_item);
//setListAdapter(new ArrayAdapter(this, R.layout.list_item, pallette));
Log.d("picklist","Switch to database list");
picklist.clear();
Log.d("picklist","get number of options");
int colurs=pallette.getCount();
Log.d("Edit Rec","Pallete count ="+Integer.toString(colurs));
for (int ix=0; ix<colurs;ix++)
{
picklist.add(pallette.getString(1));
}
Log.d("Edit rec","Create dropdown");
picklist.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mOptid.setAdapter(picklist);
mOptid.setOnItemSelectedListener(new OptItemSelectedListener());
Log.d("onCreate", "Find RowId");
mRowId=savedInstanceState != null
? savedInstanceState.getLong(NamesDbAdapter.KEY_ROWID)
: -1;
registerButtonListeners();
}
This is extracted from an activity 'NamesEditActivity' called from the main activity with an Intent, adapted from Donn Felker's book on android. The options table is created in the database as part of the onCreate class.
Inspecting the LogCat screen in Eclipse (version 3.7.0) the next line reports;
Activity Launch timeout has expired, giving up wake lock!
Why should the int declaration and initialisation not work, or is the problem elsewhere, and, am I on the right lines to create a Spinner using the data from SQLite?