I am creating an android app in which m displaying rows from the database in a table layout. In these rows i am displaying the row id and two columns from the database. I have put an on click event on the rows. what i want is now to get the id value of the specific row on which the user clicks and then display all the details from the database based on that row id... i know the part of displaying from the database by select statement. m not able to capture the row id in the onclick event... how do i do that??? anyone has any idea please help!!! here is the code for displaying details in the row...
Cursor cursor=database.rawQuery("select * from "+AllValuesTable+" ", null);
Integer index0=cursor.getColumnIndex("ROWID");
Integer index1 = cursor.getColumnIndex("appln_no");
Integer index2 = cursor.getColumnIndex("app_fname");
if(cursor.getCount()>0)
{
cursor.moveToFirst();
do
{
row=new TableRow(this);
row.setId(100);
row.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
//setting the first column
firstCol=new TextView(this);
firstCol.setText(cursor.getString(index0));
rowid=cursor.getInt(index0);
firstCol.setTextSize(16);
firstCol.setTextColor(Color.BLACK);
firstCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
row.addView(firstCol); //adding coloumn to row
// Setting up the second coloumn parameters
secondCol=new TextView(this);
secondCol.setText(cursor.getString(index1));
secondCol.setTextColor(Color.BLACK);
secondCol.setTextSize(16);
secondCol.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
row.addView(secondCol); //adding coloumn to row
// Setting up the third coloumn parameters
thirdCol=new TextView(this);
thirdCol.setText(cursor.getString(index2));
thirdCol.setTextColor(Color.BLACK);
thirdCol.setTextSize(16);
thirdCol.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
row.addView(thirdCol);
No comments:
Post a Comment