user45678
user45678

Reputation: 1514

How to customize TextView inside LayoutInflater

I have a TextView inside this layout inflater which i want to customize. What can be the easy way other than implementing getView()

private ViewGroup buildHeader() {
        LayoutInflater infalter = getLayoutInflater();
        ViewGroup header = (ViewGroup) infalter.inflate(R.layout.listitem_header, getListView(), false);

        //TEXT VIEW SET COLOR

        header.setEnabled(false);
        return(header);
      }

Upvotes: 0

Views: 151

Answers (1)

Simas
Simas

Reputation: 44158

What inflater does is inflate the layout you specified to the view hierarchy. In other words the inflater builds the objects (views) located in the layout specified, so they can be then used.

Once that is done you can find the views located in that layout with findViewById and manipulate them.

So if you have a layout that consists of:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <TextView
        android:id="myTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>

You can get and use your TextView like this:

TextView textView = (TextView) header.findViewById(R.id.myTextView);
textView.setText("Something"):
textView.setColor(Color.RED);

Upvotes: 4

Related Questions