2012-10-05 37 views
5

我正在開發Android中使用網格視圖的商店的客戶詳細信息。我使用我的數據庫獲取我的客戶的詳細信息。我需要更新使用一個警告框進入庫存量在執行交易的客戶處理的股票..從gridview更新數據庫使用android中的alertbox彈出

customergrid.xml

<?xml version="1.0" encoding="utf-8"?> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/tab1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <GridView 
      android:id="@+id/grid" 
      android:layout_width="fill_parent" 
      android:layout_height="357dp" 
      android:numColumns="1" 
      android:stretchMode="columnWidth" /> 

     <Button 
      android:id="@+id/cancel" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="cancel" /> 

    </LinearLayout> 

而且,對於每一行我已經使用自定義XML文件..

customerrow.xml

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <TableRow> 
     <TextView 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      android:id="@+id/row_ID" 
      android:padding="5px" 
      android:layout_weight="1" /> 
     <TextView 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      android:id="@+id/key_ID" 
      android:padding="5px" 
      android:layout_weight="1" /> 
     <TextView 
      android:layout_width="50px" 
      android:layout_height="wrap_content" 
      android:id="@+id/key_Description" 
      android:padding="5px" 
      android:layout_weight="1" /> 
    </TableRow> 
</TableLayout> 

而且我已經用在onCreate()方法customergrid.xml,並在網格CR使用customerrow.xml如下面的代碼..

public void FillGrid() { 
    DatabaseHelper sqdb = new DatabaseHelper(this); 
    sqdb.openDataBase(); 
    Cursor cursor; 
    GridView grid = (GridView) findViewById(R.id.grvData); 
    cursor = sqdb.getGridData(); 
    sqdb.close(); 
    if (cursor != null) { 
     startManagingCursor(cursor); 
     SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
      R.layout.customerrow, cursor, new String[] { CustomerActivity.KEY_ROW_ID, 
      CustomerActivity.KEY_ID, CustomerActivity.KEY_DESCRIPTION }, new int[] { 
      R.id.txtGrv_id, R.id.txtGrvid, R.id.txtGrvDescription }); 
     adapter.setViewResource(R.layout.gridlayout); 
     grid.setAdapter(adapter); 
} 

最後我用一個編輯框的警報框獲取客戶庫存量的輸入。我用這個那個任務..

grid.setOnItemClickListener(new OnItemClickListener() { 

    public void onItemClick(AdapterView<?> parent, View view, int position, long arg3) { 
     AlertDialog.Builder b=new AlertDialog.Builder(MarkSheet.this); 
     b.setTitle("Employee Details"); 
     LayoutInflater li=LayoutInflater.from(MarkSheet.this); 
     View v=li.inflate(R.layout.dialog, null); 
     b.setIcon(android.R.drawable.ic_input_get); 
     b.setView(v); 
     final TextView txtName=(TextView)v.findViewById(R.id.txtName); 
     final EditText Quantity=(EditText)v.findViewById(R.id.Quantity); 

     // Here I need to update the table while clicking the positive button, if I click negative button I need to cancel the Dialog box.. 

    } 
}); 

人幫助我完成這個任務..

回答

0

你可以找到更新數據庫表here的代碼,並警告框的概念here

您需要從單擊「確定」按鈕的代碼中調用sqlite的更新方法。

+0

在我的對話框,我必須執行兩個編輯框用於輸入產品名稱的產品的價值和數量。並且每個Editbox將保留相應的TextView。在例子中,我只能得到一個Editbox。我怎樣才能得到2 Textview,2 Edittext和2按鈕(提交和取消)的對話框.. – MGR