Mahad Ruush
Mahad Ruush

Reputation: 53

How to inflate textView as layout

I have been trying to inflate the below xml file but not having a luck,kindly point me to the right direction.I need to inflate and then add it to my array adapter.

        TextView footerView = null;
        View row = null;



        if (null == footerView) {

            LayoutInflater inflater =  getLayoutInflater();
            row =  inflater.inflate(R.layout.footer_view,null);
            footerView = (TextView)row.findViewById(R.id.footerView);
            setContentView(footerView);


            return;
        }


        getListView().addFooterView(footerView);


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/footerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/add_new_todo_item_string"
    android:textSize="24sp" >

</TextView>

Upvotes: 1

Views: 3151

Answers (1)

Mahad Ruush
Mahad Ruush

Reputation: 53

Resolved The below code has worked and solved my problem

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row = inflater.inflate(R.layout.footer_view, getListView(), false);
    footerView = (TextView) row.findViewById(R.id.footerView);

    // TODO - Add footerView to ListView

    getListView().addFooterView(footerView);

Upvotes: 2

Related Questions