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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:59+00:00 2026-05-27T22:06:59+00:00

As mentioned in topic, I have some Views, e.g. a TableRow with always the

  • 0

As mentioned in topic, I have some Views, e.g. a TableRow with always the same background used as topic, or a special TableRow containing a TextView with some special styles/properties. These Views are set dynamically, so it’s problematic to use a XML for this. As I read it’s not possible to set styles programmatically too. So what’s the best way to solve that?

Possibility 1:
I use and instance derived Views, like this:

public class TopicTableRow extends TableRow {

    public TopicTableRow(Context context) {
        super(context);

        setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        setBackgroundColor(Color.parseColor("#777777"));
        setClickable(false);
    }
} 

Possibility 2:
I could create a valid xml template with a special layout I never use in the application, containing the needed Views which have already all assigned styles. Afterward I access the needed Views by R.id….
But this method seems to be very dilettante to me.

I don’t think that those 2 possibilities are the “real” Android way to do this, so how is this usually done?

  • 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-27T22:06:59+00:00Added an answer on May 27, 2026 at 10:06 pm

    If you want to set specific styles for groups of elements, you can use the themes and styles concepts in android.

    You can read up on them here: http://developer.android.com/guide/topics/ui/themes.html

    It is not possible though to change the style attribute of a view programatically.

    Therefore the android way is probably to create the Views you need in XML and use a LayoutInflater to get create an ‘java’ version of the xml view. This allows you to reuse the component and fill it with apropriate data for as many rows as you would like.

    Button view = (Button) LayoutInflater.from(this).inflate(R.layout.textViewFromWeb, null);

    I hope this will be of use to you!

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

Sidebar

Related Questions

There have already been some questions about this topic (for instance Expression.Invoke in Entity
I have search for the topic mentioned above but I didn't find good satisfying
As i've mentioned in topic. I have WCF Rest Service, and ASP.NET MVC3 client.
I have seen this mentioned a few times and I am not clear on
I have not used PackedArray before, but just started looking at using them from
The topic has already been on the table in some previous questions. New elements
Let's say you have a Fortran 90 module containing lots of variables, functions and
I'm trying to construct a social network graph of twitter users who have mentioned
There are several posts on the internet for the same topic and I am
I am aware that a thousand and one questions relating to this topic have

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.