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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:50:54+00:00 2026-06-04T17:50:54+00:00

My app generates 2 different lists, one uses the default ListView style as the

  • 0

My app generates 2 different lists, one uses the default ListView style as the ListView rows contain no TextView inside of them. The other list uses a custom CursorAdapter and has a TextView inside each row. All I want to do is make it so that the margins and text size are exactly the same for both lists.

My first list is using a standard ListView with no TextView inside each row, here is what it looks like:

enter image description here

Here is the code to generate it:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.records);

    DatabaseHandler db = new DatabaseHandler(this);
    ArrayList<String> records = db.getRecords(this);

    this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, records));
} 

Here is the xml file for it:

<?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" >

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

</LinearLayout>

My second list is using a ListView with a TextView inside each row that is generated via a custom `CursorAdapter, here is what it looks like:

enter image description here

Here is the code to generate it:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.achievements);

    DatabaseHandler db = new DatabaseHandler(this);
    Cursor cursor = db.getAchievements(this);
    AchievementAdapter cursorAdapter = new AchievementAdapter(this, cursor);

    this.setListAdapter(cursorAdapter);
} 

private class AchievementAdapter extends CursorAdapter {
    public AchievementAdapter(Context context, Cursor c) {
        super(context, c);
    }

    @Override
    public void bindView(View v, Context context, Cursor cursor) {
        TextView tv = (TextView) v.findViewById(R.id.achView1);

        if(cursor.getString(cursor.getColumnIndex("completed")).equals("yes")) {
            tv.setText(cursor.getString(cursor.getColumnIndex("name"))+" (completed)");
            tv.setTextColor(Color.GREEN);
        }
        else {
            tv.setText(cursor.getString(cursor.getColumnIndex("name")));
        }
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.achievements_item, parent, false);
        return v;
    }
}   

Here is the achievements xml file for it:

<?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" >

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

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text=""/>

</LinearLayout>

Here is the achievements_item xml for it:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/achView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="" />

</LinearLayout>

Basically I just want these 2 lists to look exactly the same. Is there a way to do it so that the TextView inherits the default ListView row style? Or am I going to have to play with the margins and everything 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-04T17:50:56+00:00Added an answer on June 4, 2026 at 5:50 pm

    Just copy the attributes of the TextView from the default ListView layout android.R.layout.simple_list_item_1 and use them on your own row layout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <TextView
            android:id="@+id/achView1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:gravity="center_vertical"
            android:paddingLeft="6dip"
            android:minHeight="?android:attr/listPreferredItemHeight" />
    
    </LinearLayout>
    

    Also, if all you want for the customized ListView row layout is a TextView, you could remove the parent LinearLayout so you don’t have an extra View in the layout

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

Sidebar

Related Questions

I have an app which generates some files in the app directories I need
I have an app that generates invoices in the form of PDF files stored
Settings.settings generates Settings.Designer.cs which presumably generates app.config which then is copied to output directory
I want to build an app which generates a notification (like SMS -> mobile
I have a Tcl/Tk app that generates many forms and would like to be
Let's say I have a solution involving an iPhone app that generates some information
My application generates binary data (compressed xml) and saves it to the Google App
I'm making a custom generator that generates a new rails app, and I do
Every time I change the Core Data model for my app, it generates an
I have been developing some Django app and there's some duplicated code for different

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.