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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:41:03+00:00 2026-05-29T04:41:03+00:00

I have a TAbleLayout in my XML with 1 row i.e. te headings row.

  • 0

I have a TAbleLayout in my XML with 1 row i.e. te headings row. Other all rows, I add dynamically. I want to make a row selected on clicking it & on touching it. I added clickListener to each row and am able to trap click event. But when the mouse is pressed or kept pressed, I see color change, then again it comes to normal color. I want the color to stay changed until I click other row or click somewhere else to deactivate the selected row.

My selector XML code :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!--  Active state -->  
<item android:state_selected="true" android:state_focused="false"
      android:state_pressed="false" android:drawable="@android:color/transparent" />      
<!--  Inactive state-->  
<item android:state_selected="false" android:state_focused="false"
      android:state_pressed="false" android:drawable="@android:color/transparent" /> 
 <!--  Pressed state --> 
 <item android:state_pressed="true" android:drawable="@color/yellow" />

<!--  Selected state (using d-pad) -->  
 <item android:state_focused="true" android:state_selected="true"
       android:state_pressed="false" android:drawable="@color/yellow" />

My Java code where I generate rows dynamically :

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

    tv.setTextColor(Color.WHITE);
    tv.setPadding(20, 0, 0, 0);

    tr.setPadding(0, 1, 0, 1);
    //tr.setBackgroundColor(Color.TRANSPARENT);
    tr.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.tablerowselector));
    tr.setId(rowId);
    tr.setClickable(true);
    tr.setFocusable(true); // Added thinking that if its not focusable then it can't be selected, but makes no difference
    tr.setOnClickListener(this);
    tr.addView(tv);
}

If I handle in clickListener event, and set Background color of row based on setting prevRowSelected and currRowSelected logic, that works. But how to make selector work and why it is not working ? Can’t selector work the way am trying to achieve it ?

Thanks

Any help is 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-29T04:41:06+00:00Added an answer on May 29, 2026 at 4:41 am

    Friends, selector, doesn’t work as I had expected. So have handled it programmatically using apprpriate logic and setting row’s color.

    Thanks to all.

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

Sidebar

Related Questions

I have a layout that contains a TableLayout with three rows. Each row has
I have list view with custom row layout (list_row.xml) that contains CheckBox element: <TableLayout
I have the following problem spanning dynamically added rows to a TableLayout inside a
I've got a problem. I wish to add rows dynamically to a TableLayout .
I have a TableLayout in the xml that has a row. I am adding
I have a TableLayout defined in my xml with three columns and four rows
I have tableLayout filled with a lot of rows (in xml). I wrapped it
In my XML, I have a TableLayout with only 1 TableRow i.e. the heading.
I have a layout issue. What I do is this: create TableLayout in xml
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

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.