Necesidad de seleccionar datos guardados de Sqlite en el control Spinner

I have a Spinner Control bind with data from Sqllite during the Page Load as given below.

public void BindSpinner() {
        ArrayList<HashMap<String, String>> alist = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> map = new HashMap<String, String>();
        Cursor cursor;
        delivary_helper deliveryHelper;
        SimpleAdapter simpleAdapter;
        deliveryHelper = new delivary_helper(this);
        cursor = deliveryHelper.GetProblemCodes();
        cursor.moveToFirst();

        for (int i = 0; i < cursor.getCount(); i++) {
            map = new HashMap<String, String>();

            map.put("Deliv_Issue2_PKProblemCode",
                    cursor.getString(cursor.getColumnIndex("PKProblemCode")));
            map.put("Deliv_Issue2_ProblemCode",
                    cursor.getString(cursor.getColumnIndex("ProblemCode")));
            map.put("Deliv_Issue2_ProblemCodeDescription", cursor
                    .getString(cursor.getColumnIndex("ProblemCodeDescription")));
            map.put("Deliv_Issue2_VWReturn",
                    cursor.getString(cursor.getColumnIndex("VWReturn")));
            alist.add(map);
            cursor.moveToNext();
        }

        simpleAdapter = new SimpleAdapter(this, alist,
                R.layout.delivery_issue_2_spinner_row, new String[] {
                        "Deliv_Issue2_PKProblemCode",
                        "Deliv_Issue2_ProblemCode",
                        "Deliv_Issue2_ProblemCodeDescription",
                        "Deliv_Issue2_VWReturn" }, new int[] {
                        R.id.tvDelivIssue2PKProblemCode,
                        R.id.tvDelivIssue2ProblemCode,
                        R.id.tvDelivIssue2ProblemCodeDescription,
                        R.id.tvDelivIssue2VWReturn });
        delivery_line_problem.setAdapter(simpleAdapter);
    }

I have Saved the ID of the Selected item in the Sqllite database table.

The Problem is that when i return to the same Page after saving the Spinner control data and going throught the other pages,I am not able to get selected the saved data in the Spinner control.How can I make selected the item that i have saved and also need to fully bind the spinner with ohter data behind.

Will any one provide me a solution.

preguntado el 08 de noviembre de 11 a las 14:11

1 Respuestas

If I'm understanding you correctly, you should be able to just set an OnItemSelectedListener on your spinner. Whenever an item is selected, save it to an instance variable in your activity. That way you'll always know the last item that was selected. So something like this:

yourSpinner.setOnItemSelectedSpinner(new AdapterView.OnItemSelectedListener(){
   public void onItemSelected (AdapterView<?> parent, View view, int position, long id){
     lastItemSelected = id;
   }
   public  void onNothingSelected (AdapterView<?> parent){
     //do nothing here
   }
 });

respondido 08 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.