I want to insert a TextView into a LinearLayout that’s in a different XML file that is being used as layout for a ListView. But it seems that I can’t access the LinearLayout that’s in the other XML file.
I run a loop that gets category titles, and for each title I wanna create a TextView with the title.
How I insert the TextView
LinearLayout Layout = (LinearLayout) findViewById(R.id.itemDesign); //When debugging I can see "Layout" is just null. itemDesign is also not in main.xml.
TextView title = new TextView(this);
title.setText(CatName);
Layout.addView(title);
XML used by ListView “single_list_item.xml”
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/itemDesign"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Name Label -->
<TextView android:id="@+id/name_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="25dip"
android:textStyle="bold"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textColor="#43bd00"/>
<!-- Description Label -->
<TextView android:id="@+id/email_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#acacac"/>
</LinearLayout>
It sounds like you need to inflate your view. In
getView()of adapter classThen to access your
TextViewsAll about LayoutInflater