Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating database from gridview using an alertbox popup in android
    text
    copied!<p>I'm developing an Customer details for a shop using Grid view in android. I get the details of my Customers using my Database. I need to update the Stocks handled by the Customer using an alert box for entering the Stock Quantity while performing the Transaction..</p> <p>customergrid.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" &gt; &lt;GridView android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="357dp" android:numColumns="1" android:stretchMode="columnWidth" /&gt; &lt;Button android:id="@+id/cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="cancel" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>And, for each Row I have used a customized Xml file..</p> <p>customerrow.xml</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TableRow&gt; &lt;TextView android:layout_width="50px" android:layout_height="wrap_content" android:id="@+id/row_ID" android:padding="5px" android:layout_weight="1" /&gt; &lt;TextView android:layout_width="50px" android:layout_height="wrap_content" android:id="@+id/key_ID" android:padding="5px" android:layout_weight="1" /&gt; &lt;TextView android:layout_width="50px" android:layout_height="wrap_content" android:id="@+id/key_Description" android:padding="5px" android:layout_weight="1" /&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; </code></pre> <p>And I have Used customergrid.xml on the Oncreate() method and use customerrow.xml in the Grid creation like as the following code..</p> <pre><code> 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); } </code></pre> <p>And finally I used alert box with an editbox for getting the input of Customer's Stock Quantity. I use this for that task..</p> <pre><code>grid.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; 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.. } }); </code></pre> <p>Anybody help me for Complete this task..</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload