android - Class from XML layout that can be instantiated in the main activity -
so have xml file
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10sp" android:id="@+id/lengthlayout" android:background="@color/gray2" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" > <edittext android:id="@+id/inputlength" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="0.3" android:hint="@string/temperaturehint" android:inputtype="number" android:textsize="30sp" tools:ignore="nestedweights" /> <spinner android:id="@+id/lengthunits" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="0.7" /> </linearlayout> <view android:layout_width="fill_parent" android:layout_height="15dp" /> <linearlayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal" > <listview android:layout_width="match_parent" android:layout_height="wrap_content" android:verticalspacing="10sp" android:horizontalspacing="10dp" android:gravity="center" android:id="@+id/results_length" android:divider="@android:color/transparent" android:dividerheight="5sp" > </listview> </linearlayout> </linearlayout>
and want create class use resources xml file. when class instantiated in main activity add view app .
public class lengthfragment extends view implements onclicklistener, onitemselectedlistener{ context rcontext; public lengthfragment(context context){ super(context); rcontext = context; inflate(context, r.layout.view_length, null); }
and doing in main activity
lengthfragment lf = new lengthfragment(testapp.this);
i have tried passing in inflator of main activity lengthfragment , inflating view using inflator doesnt work gives me blank view. thanks.
also works when in main activity linearlayout l1 = (linearlayout) getlayoutinflater().inflate(r.layout.view_length, null);
but want create view outside of main acttivity instantiaing class in main activity.
Comments
Post a Comment