2015-06-30 91 views
1

我已經寫了一個程序,以從sqlite數據庫中獲取一些值,並填充內部微調,這是完美的工作,但我想顯示從微調選定的項目變成不同的活動,我所得到的是一個空值或[email protected],所以如何將其轉換爲字符串?如何獲取從sqlite數據庫填充spinner內選定的項目

需要一些幫助

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); 

在按鈕點擊保存我這樣做的記錄,acName是對此我將微調變量,我也試圖把裏面acName虛值,作爲acName =「 1「,這是正確顯示。

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); 


         } 

        } 
       }); 

謝謝

回答

0

好吧,我自己得到的回答上述問題

我這樣做是爲了讓選擇微調項的值

Cursor acNameCur=(Cursor)spinnerAccountName.getSelectedItem(); 
String accountNamecol=acNameCur.getString(acNameCur.getColumnIndex 
(DbListHelper.ACCOUNT_NAME)); 
相關問題