Skip to content Skip to sidebar Skip to footer

Functional Clickable Tablerows That Are Created Dynamically

I saw this link (http://stackoverflow.com/questions/6603868/android-onclicklistener-and-table-layout) which seems like it works for the person asking the question. That being said,

Solution 1:

Bottom Line: I figured it out!

Basing my solution from the link I posted in the question, I realized that I needed to make a textview object in order to see a cell's data! So here is my code, in connection to the code above that has remained unchanged!

introwNumCount= table.getChildCount();
    for(intcount=1; count < rowNumCount; count++) {
        Viewv= table.getChildAt(count);
        if(v instanceof TableRow) {
            finalTableRowclickRow= (TableRow)v;
            introwCount= clickRow.getChildCount();
            v.setOnClickListener(newOnClickListener() {
                publicvoidonClick(View v) {
                    Contextcontext= getTabHost().getContext();
                    TableRowrow= (TableRow)v;
                    TextViewtv= (TextView)row.getChildAt(0);
                    CharSequencetext="Lot VALUE Selected: " + tv.getText();
                    intduration= Toast.LENGTH_SHORT;
                    Toast.makeText(context, text, duration).show();
                }
            });
        }
    }

Like I said, I only needed to grab the first columns data, thus the row.getChildAt(0); line! So I know nobody probably even had the chance to answer this question yet, but I hope my answer can help others in the future!

Rationale to the question, "Why not just use a listview?" Answer: I think for what I'm making, a tabular format looks much better.

While I may not make a huge change to my code's setup, I am ALWAYS open to hear changes that could help improve my code! I love this community!

Post a Comment for "Functional Clickable Tablerows That Are Created Dynamically"