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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:31:12+00:00 2026-06-12T15:31:12+00:00

I have to create a list whose list items have 2 lines of text.

  • 0

I have to create a list whose list items have 2 lines of text. I started building a custom list item, but then I discovered the TwoLineListItem component. I wrote this code:

pageFilterResultView=new TwoLineListItem(containerActivity);
pageFilterResultView.getText1().setText("Test");

However, getText1 returns null, and the second line throws a NullPointerException. So I thought I need to use an inflated layout instead of a constructor. The TwoLineListItem documentation specifies I can use the android.R.layout.two_line_list_item resource for the layout, so I changed the code to:

LayoutInflater inflater=(LayoutInflater)containerActivity.
        getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pageFilterResultView=(TwoLineListItem)inflater.inflate(android.R.
        layout.two_line_list_item,null);
pageFilterResultView.getText1().setText("Test");

However, this throws a ClassCastException because the layout is actually a LinearLayout. TwoLineListItem inherits from RelativeLayout, so I can’t even cast the layout to a higher class in the hierarchy.

So the question is: How do I use TwoLineListItem correctly? Do I have to create my own custom layout for it? If so, what’s the point of this component if I still have to do all the work of creating a list item by myself?

  • 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-06-12T15:31:14+00:00Added an answer on June 12, 2026 at 3:31 pm

    How do I use TwoLineListItem correctly?

    The TwoLineListItem widget is a facade over two TextViews that have to be provided by you. To use the TwoLineListItem in a ListView‘s row you’ll need a row layout where you have the TwoLineListItem widget with two(at least) TextView children with specific ids(android.R.id.text1 and android.R.id.text2). Something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <TextView
            android:id="@android:id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <TextView
            android:id="@android:id/text2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:layout_below="@android:id/text1"/>
    
    </TwoLineListItem>
    

    Then you can use it in the getView() method like you did:

    pageFilterResultView=(TwoLineListItem)inflater.inflate(R.layout.the_layout_file_above,null);
    pageFilterResultView.getText1().setText("Test");
    

    Of course you have the possibility of using an included layout file as the child of the TwoLineListItem(as long as you have the two TextViews with the required ids):

    <?xml version="1.0" encoding="utf-8"?>
    <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <!-- the android version of the two line layout -->
        <include layout="@android:layout/two_line_list_item" />
    
    </TwoLineListItem>
    

    but this just increases the layout depth and should be avoided.

    If so, what’s the point of this component if I still have to do all
    the work of creating a list item by myself?

    Judging by the fact that you can’t use this widget programmatically, I don’t see the need for this component either.

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

Sidebar

Related Questions

I have a list of items. When I create the list each item has
I have create a listview of Contact numbers , the list item contains the
OK, so I have learned how to create a list, view items in the
We have some code which creates a python list and then appends data items
I am trying to create a list item layout with 4 items. It is
Whenever I use permutations, I have to create a list of the permutations because
Here's my problem: I have do create a menu/list of actions (which would be
I have the following code. I need to create list separators before A elements,
I have to create LinearLayouts dinamically according to an Entity List. The Layouts are
I have an the following class I'm trying to create a list of with

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.