JSONArray json=new JSONArray(data);
for(int i=0;i<json.length(); i++)
{
k=json.length();
rowId = i;
JSONObject obj=json.getJSONObject(i);
pname=obj.getString("ProductName");//database values
quantity= obj.getString("Quantity");
id = Integer.toString(k);
TableRow tr = new TableRow(this);
tr.setId(i);
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
TextView labelID = new TextView(this);//header is SI:NO
labelID.setText(id);
labelID.setPadding(2, 5, 5, 0);
labelID.setLeft(50);
labelID.setTextColor(Color.BLACK);
tr.addView(labelID);
TextView labelNAME = new TextView(this);//header is PRODUCT NAME
labelNAME.setText(pname);
labelNAME.setRight(10);
labelNAME.setPadding(2, 8, 5, 0);
labelNAME.setTextColor(Color.BLACK);
tr.addView(labelNAME);
labelWEIGHT = new TextView(this);//header is QUANTITY
// labelWEIGHT.setId(200 + count);
labelWEIGHT.setPadding(2, 6, 5, 0);
labelWEIGHT.setText(quantity.toString());
labelWEIGHT.setTextColor(Color.BLACK);
tr.addView(labelWEIGHT);
labelPRICE = new EditText(this);//header is PRICE...here i need to enter values and save in db
labelPRICE.setTextColor(Color.BLACK);
labelPRICE.setPadding(2, 6, 5, 0);
labelPRICE.setId(Integer.valueOf(rowId));
ar1[i]=rowId;//row id
tr.addView(labelPRICE);
tl.addView(tr, new TableLayout.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
count++;}
Basically,I'm a beginner in android, and thus I need a help in doing tablelayout program with textview and edittext.I'm not able to store the user entered edittext value in the database .I tried to get the row id of each row but couldn't get that.Can anyone please help me.
This is my layout.