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

  • Home
  • SEARCH
  • 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 9188405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:59:53+00:00 2026-06-17T19:59:53+00:00

I am trying to change the alignment of the text in ListView programmatically instead

  • 0

I am trying to change the alignment of the text in ListView programmatically instead of changing the xml file.

Here is my row_listview.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textViewRowList" 
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:textSize="20sp"
    android:paddingLeft="6dip"
    android:paddingRight="6dip" 
    android:gravity="left" 
    android:textColor="#330033"
    android:textStyle="bold"/>

And activity_main.xml has following ListView defined there

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@null"
    android:dividerHeight="0dp"
    tools:listitem="@android:layout/simple_list_item_1" 
    android:background= "#FF6600">
 </ListView>

So in my mainactivity.java I am trying to change the alignment of the text in listview at runtime when user clicks a button on my activity

private ListView lv;
private TextView tvRowListView;
lv.setAdapter(new ArrayAdapter<String>(this,R.layout.row_listview, sampleStringArray));
tvRowListView = (TextView) findViewById(R.id.textViewRowList);
tvRowListView.setGravity(Gravity.CENTER);

The last line above is however throwing nullpointerexception. I am not sure why. Can someone throw some ideas/solutions here.

  • 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-17T19:59:54+00:00Added an answer on June 17, 2026 at 7:59 pm

    your textViewRowList exists for every item in that list, if you want to change it’s properties you will need to do it in the Adapter in getView which means you will need to make a custom adapter

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

Sidebar

Related Questions

I'm trying to change some text in a .CSV file. StreamReader sReader = new
I'm trying to change the text alignment and the font size of a DataGridView.
I was trying to change the alignment of text. This is what i have:
I'm trying to change the color of a DataGridTextColumn. Here's what I'm doing: <DataGridTextColumn
I'm trying to change the menu here from mouse over to a on click
I'm trying to change the alignment of a UILabel on the main thread like
I'm trying to change the font of text in one of the activities of
I'm trying to capture assignment operations from a text file using 'java.util.regex.Pattern'. I've been
I'm trying change an input mask for textbox when the the check box has
Am trying to change the button frame according to the orientation change but button

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.