2015-03-19 67 views
-1

我是android的新手。我有2个表格用于存储和显示微调数据,另一个表格用于存储选定的微调值,现在我想以android`下面的代码的listview形式显示sqlite数据库表格内容。在列表视图中显示sqlite内容

private View.OnClickListener mCorkyListener = new View.OnClickListener() { 
 
     public void onClick(View v) { 
 
      // do something when the button is clicked 
 

 
      Log.d("button clicked", "button clicked"); 
 

 

 
      String mac_no = my_spinners.getSelectedItem().toString(); 
 
      String incharge = my_spinnerssss.getSelectedItem().toString(); 
 
      String operator_name = my_spinnerss.getSelectedItem().toString(); 
 
      String status_of_mac = my_spinnersss.getSelectedItem().toString(); 
 
      String fullName = mac_no + " " + status_of_mac; 
 
      Log.d("fullname", fullName); 
 

 
      try { 
 
       mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null); 
 
       // mydb.delete(TABLES, null, null); 
 
       mydb.execSQL("CREATE TABLE IF NOT EXISTS " + TABLES 
 
         + " (ID INTEGER PRIMARY KEY, DATE_TIME TEXT, MACHINE_NO INTEGER, OPERATOR_NAME TEXT, STATUS TEXT, INCHARGE TEXT);"); 
 
       Calendar c = Calendar.getInstance(); 
 
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
 
       String strDate = sdf.format(c.getTime()); 
 
       Toast.makeText(getApplicationContext(), "The String Date is " + strDate, Toast.LENGTH_LONG).show(); 
 
       ContentValues data = new ContentValues(); 
 
       data.put("ID", ID); 
 
       data.put("DATE_TIME", strDate); 
 
       data.put("MACHINE_NO", mac_no); 
 
       data.put("OPERATOR_NAME", operator_name); 
 
       data.put("STATUS", status_of_mac); 
 
       data.put("INCHARGE", incharge); 
 
       if (mydb == null) { 
 
        // make sure that your db is properly initialised 
 
       } 
 
       mydb.insert("RECORD_TABLES", "nullColumnHack", data); 
 
       Log.d("Inserted into record table", "Inserted into record table"); 
 

 
       mydb.close(); 
 
      } catch (Exception e) { 
 
       Toast.makeText(getApplicationContext(), "Error in creating table", 
 
         Toast.LENGTH_LONG); 
 
      } 
 
      BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
 
      if (mBluetoothAdapter == null) { // Device does not support Bluetooth } 
 
      } 
 
      Log.d("Bluetooth Adapter is active", "Bluetooth Adapter is active"); 
 
      try { 
 
       if (!mBluetoothAdapter.isEnabled()) { 
 
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
 
        startActivityForResult(enableBtIntent, 1); 
 
        Log.d("Intent is enabled", "Intent is enabled"); 
 
       } 
 
       Log.d("Intent is correct", "Intent is correct"); 
 
      } catch (NullPointerException e) { 
 
      } 
 
      try { 
 

 

 
       Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); 
 
       if (pairedDevices.size() > 0) { 
 
        for (BluetoothDevice device : pairedDevices) { 
 
         BluetoothDevice mDevice = device; 
 
         String name = mDevice.getName(); 
 
         Log.d("mDevice", name); 
 

 
         ConnectThread mConnectThread = new ConnectThread(mDevice, fullName); 
 
         mConnectThread.start(); 
 
         exportDB(); 
 
         try { 
 
          mConnectThread.write(fullName); 
 
         } catch (IOException nn) { 
 
         } 
 

 

 
        } 
 
       } 
 

 
      } catch (NullPointerException n) { 
 
      } 
 

 

 
     } 
 

 

 
    };

`

回答