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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:43:26+00:00 2026-05-15T02:43:26+00:00

I have several ListActivties set up in my Android Application. What I am trying

  • 0

I have several ListActivties set up in my Android Application. What I am trying to do is set it up so the user can select the background color, the font size, and the font color through a PreferenceActivity. I have gotten everything figured out regarding the Preference activity but I can not figure out how to grab the ListView in code.

One of my ListActivities is set up in the normal way but it is required to have the android id tag “android:id=”@android:id/list””. Because of this I am unable to change it in real time. (I was trying to use findViewById(R.id.list);)

My other ListActivities use a different implementation of ArrayAdapter in order to change the layouts of each row. So in this case I have one XML file containing the ListView and another XML file defining the layout of the row. I need to be able to change the TextView in side the row XML file and the ListView in the other XML file. The reason it is set up this way is to dynamically decide what icon to put in each row and in the implementation of ArrayAdapter I had to use an inflator to get to the label ImageView. In this case I am not sure how I would use an inflator out side of that implementation.

The following is an example of what I was talking about with the second listView.

public class Routes extends ListActivity {
private String[] ROUTES;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ROUTES = getResources().getStringArray(R.array.routes);

    setContentView(R.layout.routes);
    setListAdapter(new IconicAdapter());

}

class IconicAdapter extends ArrayAdapter<String> {


    IconicAdapter() {
        super(Routes.this, R.layout.row, R.id.label, ROUTES);
    }

    public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.row, parent, false);
        TextView label = (TextView) row.findViewById(R.id.label);

        label.setText(ROUTES[position]);

        ImageView icon = (ImageView) row.findViewById(R.id.icon);
        ShapeDrawable mDrawable;

        int x = 0;
        int y = 0;
        int width = 50;
        int height = 50;

        float[] outerR = new float[] { 12, 12, 12, 12, 12, 12, 12, 12 };

        mDrawable = new ShapeDrawable(new RoundRectShape(outerR, null, null));
        mDrawable.setBounds(x, y, x + width, y+height);
        mDrawable.setPadding(25,25,25,25);



        switch(position){

        case 0:
            mDrawable.getPaint().setColor(0xffff0000);      //Red
            break;
        case 1:
            mDrawable.getPaint().setColor(0xffff0000);      //Red
            break;
        case 2:
            mDrawable.getPaint().setColor(0xff00c000);      //Green
            break;
        case 3:
            mDrawable.getPaint().setColor(0xff00c000);      //Green
            break;
        case 4:
            mDrawable.getPaint().setColor(0xff0000ff);      //Blue
            break;
        case 5:
            mDrawable.getPaint().setColor(0xff0000ff);      //Blue
            break;
        }

        icon.setBackgroundDrawable(mDrawable);
        return(row);
    }


   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">

  <ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />

</LinearLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="7px"
android:paddingLeft="6px">

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
/>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="17px"
    android:textSize="28sp"
/>

Any suggestions would be 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-15T02:43:26+00:00Added an answer on May 15, 2026 at 2:43 am

    Because of this I am unable to change
    it in real time.

    Call getListView() on your ListActivity.


    With regard to your other ListViews, I don’t understand what your question is. You inflate the rows when you need them (NOTE: not on every getView() call, please recycle your convertView). You adjust rows at that point to look how you wish, just like you are adjusting your ImageView.

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

Sidebar

Related Questions

No related questions found

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.