2012-10-05 27 views
5

में एक अलर्टबॉक्स पॉपअप का उपयोग करके ग्रिडव्यू से डेटाबेस अपडेट करना मैं एंड्रॉइड में ग्रिड व्यू का उपयोग करके एक दुकान के लिए ग्राहक विवरण विकसित कर रहा हूं। मुझे अपने डेटाबेस का उपयोग करके अपने ग्राहकों का ब्योरा मिलता है। मैं स्टॉक्स ग्राहक जबकि लेन-देन स्टॉक मात्रा में प्रवेश के लिए एक चेतावनी बॉक्स का उपयोग करके नियंत्रित किया अद्यतन करने की आवश्यकता ..एंड्रॉइड

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 प्रयुक्त और ग्रिड करोड़ में customerrow.xml का उपयोग किया है निम्नलिखित कोड के रूप में की तरह eation ..

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

और अंत में मैं के लिए ग्राहक के स्टॉक मात्रा इनपुट प्राप्त करने के लिए एक editbox के साथ चेतावनी बॉक्स का इस्तेमाल किया। मुझे लगता है कि इस काम के लिए इस का उपयोग ..

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

आपको उस कोड से स्क्लाइट की अद्यतन विधि को कॉल करने की आवश्यकता है जहां आपने "ठीक" बटन पर क्लिक किया था। इस लिंक पर

+0

मेरी संवाद बॉक्स में, मैं उत्पाद के उत्पाद का नाम के मूल्य और मात्रा में प्रवेश के लिए दो Editbox प्रदर्शन करने के लिए है । और प्रत्येक एडिटबॉक्स संबंधित टेक्स्टव्यू रखेगा। उदाहरण में मैं केवल एक संपादन बॉक्स प्राप्त कर सकता था। मैं 2 टेक्स्टव्यू, 2 एडिटेक्स्ट और 2 बटन (सबमिट और रद्द करें) के साथ संवाद बॉक्स कैसे प्राप्त कर सकता हूं .. – MGR