mardi 30 juin 2015

how to get the selected item inside spinner populated from sqlite database

I have written a program to get some values from sqlite database and populate inside spinner ,which is working perfectly , but i want to show the selected item from the spinner into a different activity , all i am getting is either a blank value or android.database.sqlite.SQLiteCursor@3456046c , so how to convert it to string ??

Need some help

int[] to = new int[] { android.R.id.text1 };
    String[] from = new String[] { DbListHelper.ACCOUNT_TYPE };
    final SimpleCursorAdapter adapter4 = new SimpleCursorAdapter(
            getBaseContext(), android.R.layout.simple_list_item_1, cursor,
            from, to) {
        public View getView(int position, View convertView, ViewGroup  
            parent) {
            View v = super.getView(position, convertView, parent);
            ((TextView) v).setTextSize(18);
            ((TextView) v).setGravity(Gravity.CENTER);
            ((TextView) v).setTextColor(Color.parseColor("#1C689C"));
            return v;
        }

    };

    adapter4.setDropDownViewResource
    (android.R.layout.simple_spinner_dropdown_item);
    spinnerType.setAdapter(adapter4);

On button click to save the records i am doing this , acName is the spinner variable which i am inserting , i also tried to put a dummy value inside acName as acName = "1" , which is showing properly .

    btnPrint.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        if(cursor.moveToFirst()){
                            do {
                                acName = 
    cursor.getString(cursor.getColumnIndex(DbListHelper.ACCOUNT_NAME));
                            } while (cursor.moveToNext());

                        }
                        vehicleNo1 = editVehicleNo1.getText().toString();

                        driverName = editDriverName.getText().toString();
                        driverCode = editDriverCode.getText().toString();
                        dieselRate = editDieselRate.getText().toString();
                        dieselQty = editDieselQty.getText().toString();
                        amount = editAmount.getText().toString();
                        referenceNo = editReferenceNo.getText().toString();
                        noOfCopies = editNoOfCopies.getText().toString();
                        remark = editRemark.getText().toString();
                        transactionID = imeiCode + "" + dateTime;

                        if (spinnerData.equals("") || vehicleNo1.equals("")
                                || spinnerAccountName.equals("")
                                || spinnerFuelRate.equals("")
                                || driverName.equals("")
                                || dieselQty.equals("")
                                || dieselRate.equals("")
                                || amount.equals("")
                                || referenceNo.equals("")) {
                            Toast.makeText(getBaseContext(),
                                    "Please fill all the fields",
                                    Toast.LENGTH_LONG).show();
                        }
                        else if (noOfCopies.equals("")) {
                            Toast.makeText(getBaseContext(),
                                    "Please enter any value",
                                    Toast.LENGTH_LONG).show();
                        } else {
                            long id = listHelper.insertPumpData(
                                    acName, vehicleNo1, 
                                    driverName,driverCode,
                                    dieselRate, dieselQty, amount + " Rs",
                                    referenceNo, noOfCopies, date, time,
                                    transactionID);


                        }

                    }
                });

Thank You

Aucun commentaire:

Enregistrer un commentaire