Midhun
Midhun

Reputation: 178

How get a table column value of a specific row in android

This is my code inside a for loop. I have 10 items but I could select only 5 rows. The rest is not clickable. Any one please find me a solution.

final TableRow tablerow11 = (TableRow) table.getChildAt(i);
tablerow11.setClickable(true);
final TextView sample = (TextView) tablerow11.getChildAt(0);
Log.d("finalI", String.valueOf(i));
sample.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        Log.d("LOG","clicked");
    }
});

Upvotes: 0

Views: 2277

Answers (1)

user7592671
user7592671

Reputation: 310

I'm not sure if you still need an answer, but this may help. It is not clear if you want to get the table column value on click or if you are just wanting to loop through all the rows in the table..

but if it is the latter, this may help.

        //loop through table and get the Child count
        for(int i =0,j = tblSomeTable.getChildCount(); i< j ;i++)
        {
            try {
                //get Child views of the table with table.getChildAt(int index), this returns a view
                //cast it to a TextView        
                View view = tblSomeTable.getChildAt(i);
                TableRow r = (TableRow) view;
                //in this row (row i) of the table get the child element(column) where the first column would have a value of 0
                TextView getCatno = (TextView) r.getChildAt(1);
                String CatNo = getCatno.getText().toString();

This code basically loops through all of the items in a table one by one, then gets the child views of the table in a specific row. Then using getChildAt in the row, you can get a column value of that row. This example gets the value of the second column in the table of row i

Upvotes: 1

Related Questions