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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:37:44+00:00 2026-05-28T17:37:44+00:00

In my XML, I have a TableLayout with only 1 TableRow i.e. the heading.

  • 0

In my XML, I have a TableLayout with only 1 TableRow i.e. the heading. Other all rows I add dynamically setting BackgroundColor (LTGray) for TableRow & TextColor for TextViews in it . I also handle click event on each row.

private void createView(TableRow tr, TextView tv, String data, int rowId) {
    tv.setText(data);

    //tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    tv.setTextColor(Color.BLACK);
    tv.setPadding(20, 0, 0, 0);

    tr.setPadding(0, 1, 0, 1);
    tr.setBackgroundColor(Color.LTGRAY);
    tr.setId(rowId);
    tr.setClickable(true);
    tr.setOnClickListener(this);
    tr.addView(tv);
}

Reg selection :
I want to change the BackgroundColor of TableRow lets say Yellow. So if 1st row is selected it bgColor should be Yellow. Then if 3rd row is selected the 1st row’s color should turn to LTGray.

And if anywhere out of the Rows is clicked, then the selected Row (if at all) should also be de-selected. For this do I have to add the main layout clickListener OR make the row select again and it turns deselected ?

Can selector (state list drawable) work for both the ways or I got to handle it programmatically. What sort of Drawable should I use to setBackgroundDrawable in my Java Code to se the statelist drawable ?

I believe like other components for TableRow also onClick will also take care of onTouch. Please correct me if am wrong. As want to handle the same feature with touching the row also.

What is the best way to achieve the goal ? Any help is highly appreciated.

  • 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-28T17:37:45+00:00Added an answer on May 28, 2026 at 5:37 pm

    Thanks Friends,

    I managed it handling in the code itself. Added click listener to each row addd and handle the colors of selected and non-selected row accordingly.

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

Sidebar

Related Questions

I have a TabLayout. In that I have a tablelayout with dynamically added rows.
I have the following problem spanning dynamically added rows to a TableLayout inside a
Context: I have a TableLayout (created using XML), which has one TableRow, which has
I have tableLayout filled with a lot of rows (in xml). I wrapped it
I have a TableLayout defined in my xml with three columns and four rows
I have XML with a value like the following: <products> <product id=1 name=All Products>
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have the following layout for a dialog: <?xml version=1.0 encoding=utf-8?> <TableLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/categorylist
I have a TAbleLayout in my XML with 1 row i.e. te headings row.
I have a layout issue. What I do is this: create TableLayout in xml

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.