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 7949487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:00:45+00:00 2026-06-04T02:00:45+00:00

In the following code i am creating a click listener separately for two tables.

  • 0

In the following code i am creating a click listener separately for two tables. How to make a single click event for both to compare their row id’s. Because after comparing rows i have to draw a line between them.

for (i = 0; i < data.getItem().size(); i++) {

        final TableRow tr = new TableRow(this);
        final TableRow tr1 = new TableRow(this);
        tr.setPadding(2, 2, 2, 2);

        TableLayout.LayoutParams tableRowParams=
              new TableLayout.LayoutParams
              (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.FILL_PARENT);

        int leftMargin=0;
        int topMargin=2;
        int rightMargin=0;
        int bottomMargin=1;

        tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

        tr.setLayoutParams(tableRowParams);
        tr1.setLayoutParams(tableRowParams);

        match1[i]= new TextView(this);
        match1[i].setId(i);
        System.out.println(match1[i].getId());
        match1[i].setText(data.getItem().get(i));
        System.out.println(match1[i].getText().toString());
        match1[i].setTextColor(Color.WHITE);
        match1[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        match1[i].setTextSize(12);
        match1[i].setPadding(10,0,0,0);
        tr.addView(match1[i]);
        Log.e("TAG", "ID: "+match1[i].getId());
        final View row=t1.getChildAt(i);
        row.setOnClickListener(new OnClickListener(){
           public void onClick(View v){
            int row_id=t1.indexOfChild(row);
            Log.e("TAG ID for Table 1", "ID: "+row_id);
            //Toast.makeText(getBaseContext(), row_id, Toast.LENGTH_SHORT).show();
           }
        });
        t1.addView(tr, tableRowParams);

        match2[i]= new TextView(this);
        match2[i].setId(i);
        match2[i].setText(data.getTarget().get(i));
        System.out.println(match2[i].getText().toString());
        match2[i].setTextColor(Color.WHITE);
        match2[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
        match2[i].setTextSize(12);
        //match2[i].setPadding(10,0,0,0);
        tr.addView(match2[i]);
        Log.e("TAG ID For Tabel 2", "ID: "+match1[i].getId());
        final View row1=t2.getChildAt(i);
        row1.setOnClickListener(new OnClickListener(){
           public void onClick(View v){
            int row_id=t2.indexOfChild(row1);
            Log.e("TAG", "ID: "+row_id);
            //Toast.makeText(getBaseContext(), row_id, Toast.LENGTH_SHORT).show();
           }
        });
        t2.addView(tr1, tableRowParams);

        /*if(match1[i].getId() == match2[i].getId()){
            //draw.onDraw(canvas);
            Toast.makeText(this, "Yipee", Toast.LENGTH_SHORT).show();
        }else
            Toast.makeText(this, ":(((((", Toast.LENGTH_SHORT).show();*/

    }
  • 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-04T02:00:47+00:00Added an answer on June 4, 2026 at 2:00 am

    You can do it like this:

    OnClickListener listener = new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // whatever you want
        }
    };
    
    // ...
    
    row.setOnClickListener(listener);
    row1.setOnClickListener(listener);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am successfully creating a marker on click however, using the following code, I
I have the following code for creating tabs. It works at the end of
Eariler I happily used the following code for creating form elements (inside Zend_Form descendant):
I'm creating JPopUpMenu with following code: JPopupMenu popup1 = new JPopupMenu(); JPopupMenu popup2 =
I am creating a SMS app the following code is supposed to: check if
Following code iterates through many data-rows, calcs some score per row and then sorts
The following code is within an ajax call. I'm trying to make sure people
I am creating a wbsite and I have the following code in c#.net public
Let say I have the following code $(p).bind(click, function(){ alert( $(this).text() ); }); When
I have js following code. createNote() function is called when I click a Crate

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.