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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:26:14+00:00 2026-05-27T10:26:14+00:00

I’m trying to show two different views in each element of the list. Both

  • 0

I’m trying to show two different views in each element of the list. Both vews are text views, but I want one of them to be enclosed in a square with a different color. I know is possible because I’ve read about it but I’m not able to understand it properly!

Any ideas?

Thanks!

  • 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-27T10:26:15+00:00Added an answer on May 27, 2026 at 10:26 am

    You can create your own adapter for the list. The adapter is what decides how to display the items in the list.
    Here is an example:

    class MyAdapter extends ArrayAdapter<TheObjectsToPopulateYourList>{
            public MyAdapter(Context context, int textViewResourceId, ArrayList<TheObjectsToPopulateYourList]> objects) {
                super(context, textViewResourceId, objects);
            }
    
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if( convertView== null ) convertView = getLayoutInflater().inflate(R.layout.your_layout, null);
    
                TextView myTextView1 = (TextView)convertView.findViewById(R.id.yourFirstTextView);
                myTextView1.setText(getItem(position*2)); //getItem gets the item (String in this case) from the list we specified when creating the adapter.
                //position is the current position of the list, and since each position has two items, we have to multiply the position by 2 to get to the right item-list-position.
                TextView myTextView2 = (TextView)convertView.findViewById(R.id.yourSecondTextView);
                myTextView2.setText(getItem(position*2 +1 ));
                myTextView2.setBackgroundColor(0xFFFF00FF); //Any color. Use setBackgroundResource to use a resource object (drawable etc.)
    
                return convertView;
            }
        }
    

    And you also need the line-layout to contain all the elements you need (this is what will be displayed on each line of the list), let’s call it ‘thelinelayoutfile.xml’ and put it in the layout folder:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="15dp">
        <TextView 
            android:id="@+id/yourFirstTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                android:text="line1"/>
        <TextView 
            android:id="@+id/yourSecondTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
                android:text="line2"/>
    </LinearLayout>
    

    Then when you initialize your list (in your onCreate() method, perhaps?)
    You call

    //You can create the list anywhere, or use an array.
    //I will create it here, just for the sake of demonstration.
    ArrayList<String> myLines = new ArrayList<String>();
    myLines.add("item1, line1");
    myLines.add("item1, line2");
    myLines.add("item2, line1");
    myLines.add("item2, line2");
    
    //set the list adapter:
    ListView myList = (ListView)findViewById(R.id.whateveryourlistidis);
    myList.setAdapter(new MyAdapter(this, R.layout.thelinelayoutfile, myLines));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to show the soap response to UIWebview.. my soap response is, <p><img
I'm trying to select an H1 element which is the second-child in its group
I want to construct a data frame in an Rcpp function, but when I
I've tracked down a weird MySQL problem to the two different ways I was
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.