Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8292587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:32:07+00:00 2026-06-08T13:32:07+00:00

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

  • 0

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, here’s my situation.

I have a TableLayout, dynamically filled with four columns of data. The row as a whole needs to be clickable, since there are no buttons like the example linked above.

A clicked row needs to pass its first column’s(column 0) data, which is just a string. Here is the function that’s called to create a new row.

private void addLotTableRow(CharSequence [] row, int count) {
    final TableLayout table = (TableLayout) findViewById(R.id.lotsTableList);
    final TableRow tr = (TableRow) getLayoutInflater().inflate(R.layout.lotsrow, null);
    TextView tv;
    // Fill Cells
        tv = (TextView) tr.findViewById(R.id.lotCell1);//Cell 1: Lot Number
        tv.setText(row[0]);

        tv = (TextView) tr.findViewById(R.id.lotCell2);//Cell 2: Sample
        tv.setText(row[1]);

        tv = (TextView) tr.findViewById(R.id.lotCell3);//Cell 3: Inspected
        tv.setText(row[3]);

        tv = (TextView) tr.findViewById(R.id.lotCell4);//Cell 4: Total
        tv.setText(row[2]);

        table.addView(tr);
}

So I originally tried to make a tr.setOnClickListener(new View.OnclickListener() {blahblah}); in this function, right before the table.addView(tr) line. The “blah blah” was of course an onClick(View v) function. I originally would only get the last row’s data, no matter which row I clicked. Now, I’m trying to do like the link above, and produce the onclicks from a higher up function, after all the table rows have been created. I probably can give more info, but I think people can get the idea for now from this! Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:32:09+00:00Added an answer on June 8, 2026 at 1:32 pm

    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!

        int rowNumCount = table.getChildCount();
        for(int count = 1; count < rowNumCount; count++) {
            View v = table.getChildAt(count);
            if(v instanceof TableRow) {
                final TableRow clickRow = (TableRow)v;
                int rowCount = clickRow.getChildCount();
                v.setOnClickListener(new OnClickListener() {
                    public void onClick(View v) {
                        Context context = getTabHost().getContext();
                        TableRow row = (TableRow)v;
                        TextView tv = (TextView)row.getChildAt(0);
                        CharSequence text = "Lot VALUE Selected: " + tv.getText();
                        int duration = 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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading this link http://addyosmani.com/largescalejavascript/#modpattern And saw the following example. var basketModule =
I saw this: http://memeburn.com/2012/02/anonymous-is-shutting-down-the-internet/?utm_source=twitterfeed&utm_medium=twitter&utm_campaign=Feed%3A+memeburncom+%28memeburn%29 But I've seen it loads. The part I'm referring to
I've been examining HTTP 1.1 specifications and well I saw something like this: Request-Line
After reading this question , i saw the answer by Naveen containing a link
I saw this posting which explained how to get BC3 working as the diff
I saw this in our codebase the other day: link.attr('style', map({ color: '#9a4d9e', cursor:
I saw this link here: How to detect Facebook share success? with Javascript But
While I am watching the demo with the following link http://www.jetbrains.com/resharper/demos/presentation/overview/refactorings/Refactor_this_demo.htm I saw this
I load a page, saw on twitter, using a line like this: [self.webView loadRequest:[NSURLRequest
I'm using this great plugin: https://github.com/maranomynet/linkify/blob/master/1.0/jquery.linkify-1.0.js to link text manipulating the dom. The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.