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

  • Home
  • SEARCH
  • 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 6635243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:01:38+00:00 2026-05-25T23:01:38+00:00

I have a simple table layout in the .xml file. I am adding components

  • 0

I have a simple table layout in the .xml file. I am adding components to it at run-time.
Following is my code:

public class Home extends Activity{

    TextView tv1; int i;TableRow tbrow;
    String [] names = {"First Name","Last Name", "Title","Company","Phone"};
    int [] images = { R.drawable.icon,R.drawable.icon,R.drawable.star2,R.drawable.icon,R.drawable.icon}


        @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);      
        TableLayout ll=(TableLayout) findViewById(R.id.tableLayout1);


        TableRow trow=new TableRow(this);
        ImageView Image1=new ImageView(this);
        ImageView Image2=new ImageView(this);
        ImageView Image3=new ImageView(this);
        ImageView Image4=new ImageView(this);
        tv1=new TextView(this);
        trow.setClickable(true);

        Image1.setImageResource(R.drawable.blank);
        Image2.setImageResource(R.drawable.star2);
        Image3.setImageResource(R.drawable.blank);
        Image4.setImageResource(R.drawable.blank);

        tv1.setText("Brochures");
        trow.addView(Image1);
        trow.addView(tv1);
        trow.addView(Image2);
        trow.addView(Image3);
        trow.addView(Image4);
        trow.setId(0);
        ll.addView(trow);
        for(i=1;i<5;i++){
            tbrow=new TableRow(this);
            ImageView img1=new ImageView(this);
            tv1=new TextView(this);
            CheckBox chk=new CheckBox(this);
            ImageView img2=new ImageView(this);
            ImageView img3=new ImageView(this);
            img1.setImageResource(R.drawable.pdf);
            img2.setImageResource(R.drawable.blank);
            img3.setImageResource(R.drawable.blank);

            tv1.setText(""+names[i]);
            tbrow.addView(img1);
            tbrow.addView(tv1);
            tbrow.addView(chk);
            tbrow.addView(img2);
            tbrow.addView(img3);
            tbrow.setId(i);
            Log.e("TAG", "ID: "+tbrow.getId());
            tv1.setOnClickListener(new OnClickListener() {                      
                @Override
                public void onClick(View arg0) {
                    Toast.makeText(Home.this, ""+tbrow.getId(),
                            Toast.LENGTH_SHORT).show();
                    Log.e("TAG", " clicked ID: "+tbrow.getId());
                }
            });
         ll.addView(tbrow);
        }
    }
}

Whenever I click on any of the rows, the onClick() event of the last row is triggered. Instead of text view, I also tried to trigger the onClick() event for table row, but in vain.

I want to know which row is clicked. getID(), setID() won’t work.

Please 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-05-25T23:01:39+00:00Added an answer on May 25, 2026 at 11:01 pm

    Change the line

    tbrow=new TableRow(this);

    to

    final TableRow tbrow = new TableRow(this);
    

    and it will work as you expect.

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

Sidebar

Related Questions

I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
Simple problem: With the XML layout shown below, I have some views wrapped in
I have a simple GUI table-layout I'm trying to design in eclipse, but when
I have a simple table in MySql whose raison-d'être is to store logs. The
I have a simple table with autoincrementing ID's and one text column. id(int), value(nvarchar)
I have a simple table in Sybase, let's say it looks as follows: CREATE
I have a simple table view which is editable. All I need the user
I have a simple table (lets call it Table1) that has a NVARCHAR field
If I have a simple table where the data is such that the rows
Say I have a simple table that contains username, firstname, lastname. How do I

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.