android - custom layout with child -
i facing problem.
i created custom layout.
i need expand , collapse these childview on click of expandable layout. how can expandable view's in sample app.
i want add child in expandable view ,can not use of activity set child every thing in expandableview class.
//myactivity layout custom layout
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res/com.example.customview" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="fill_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <com.example.customview.expandableview android:id="@+id/ex_view1" android:layout_width="match_parent" android:layout_height="wrap_content" custom:buttontitle="details" custom:title="all staff details" custom:visibility="@integer/visible" android:orientation="vertical"> </com.example.customview.expandableview> <com.example.customview.expandableview android:id="@+id/ex_view2" android:layout_width="match_parent" android:layout_height="wrap_content" custom:title="next coming" custom:visibility="@integer/gone" /> <com.example.customview.expandableview android:id="@+id/ex_view3" android:layout_width="match_parent" android:layout_height="wrap_content" custom:title="previous record" custom:visibility="@integer/gone" /> <com.example.customview.expandableview android:id="@+id/ex_view4" android:layout_width="match_parent" android:layout_height="wrap_content" custom:buttontitle="next" custom:title="new news" custom:visibility="@integer/visible" /> </linearlayout> </scrollview> // mainlayout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:id="@+id/parent_id" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaabab" android:orientation="horizontal" > <textview android:id="@+id/tv_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:paddingbottom="15dp" android:paddingtop="15dp" android:textsize="18sp" android:textstyle="bold" /> <button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="#b7b7b8" android:drawableleft="@drawable/ic_menu_edit" android:paddingright="5dp" /> </linearlayout> <view android:layout_width="match_parent" android:layout_height="5dp" /> </linearlayout> //code
public class expandableview extends linearlayout { textview textview; button button; linearlayout parentlinear,childlinear; view view,convertview; context context; webview web; layoutinflater inflater ; view viewlay ; /** * constructor * @param context * @param attr */ public expandableview(final context context,attributeset attr) { super(context,attr); this.context = context; inflate(context,r.layout.mainlayout, this); textview =(textview)findviewbyid(r.id.tv_text); button = (button)findviewbyid(r.id.btn); parentlinear =(linearlayout)findviewbyid(r.id.parent_id); getattributes(attr); //setchildview(); } public void setchildview() { web = (webview)findviewbyid(r.id.webview); web.loadurl("file:///android_asset/info.html"); } /** * function attributes attrs.xml * @param attr */ public void getattributes(attributeset attr) { typedarray attributes = context.obtainstyledattributes(attr,r.styleable.mycustomwidget); string texttitle = attributes.getstring(r.styleable.mycustomwidget_title); textview.settext(texttitle); string textbuttontitle = attributes.getstring(r.styleable.mycustomwidget_buttontitle); button.settext(textbuttontitle); int visibility = attributes.getinteger(r.styleable.mycustomwidget_visibility, 0); button.setvisibility(visibility); attributes.recycle(); } } now need add web view inside custom layout,so doing this
<com.example.customview.expandableview android:id="@+id/ex_view1" android:layout_width="match_parent" android:layout_height="wrap_content" custom:buttontitle="details" custom:title="all staff details" custom:visibility="@integer/visible" android:orientation="vertical"> <webview android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="wrap_content" /> </com.example.customview.expandableview> problem case 1:-
if setting child webview in activity ,its working fine.i.e
//activity class
expandableone = (expandableview)findviewbyid(r.id.ex_view1); expandableone.setchildview(); but don't want set child in activity.
case 2:- want set in expandableview class
so calling method in constructor .
setchildview();//this in constructor
and remove expandableone.setchildview(); activity class....now crashing
my logcat
05-03 11:07:29.364: e/androidruntime(1336): fatal exception: main 05-03 11:07:29.364: e/androidruntime(1336): java.lang.runtimeexception: unable start activity componentinfo{com.example.customview/com.example.customview.expandableactivity}: android.view.inflateexception: binary xml file line #12: error inflating class com.example.customview.expandableview 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread.performlaunchactivity(activitythread.java:1956) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1981) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread.access$600(activitythread.java:123) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread$h.handlemessage(activitythread.java:1147) 05-03 11:07:29.364: e/androidruntime(1336): @ android.os.handler.dispatchmessage(handler.java:99) 05-03 11:07:29.364: e/androidruntime(1336): @ android.os.looper.loop(looper.java:137) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread.main(activitythread.java:4424) 05-03 11:07:29.364: e/androidruntime(1336): @ java.lang.reflect.method.invokenative(native method) 05-03 11:07:29.364: e/androidruntime(1336): @ java.lang.reflect.method.invoke(method.java:511) 05-03 11:07:29.364: e/androidruntime(1336): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 05-03 11:07:29.364: e/androidruntime(1336): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 05-03 11:07:29.364: e/androidruntime(1336): @ dalvik.system.nativestart.main(native method) 05-03 11:07:29.364: e/androidruntime(1336): caused by: android.view.inflateexception: binary xml file line #12: error inflating class com.example.customview.expandableview 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.createview(layoutinflater.java:606) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:680) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.rinflate(layoutinflater.java:739) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.rinflate(layoutinflater.java:742) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-03 11:07:29.364: e/androidruntime(1336): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:251) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activity.setcontentview(activity.java:1835) 05-03 11:07:29.364: e/androidruntime(1336): @ com.example.customview.expandableactivity.oncreate(expandableactivity.java:23) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activity.performcreate(activity.java:4465) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 05-03 11:07:29.364: e/androidruntime(1336): @ android.app.activitythread.performlaunchactivity(activitythread.java:1920) 05-03 11:07:29.364: e/androidruntime(1336): ... 11 more 05-03 11:07:29.364: e/androidruntime(1336): caused by: java.lang.reflect.invocationtargetexception 05-03 11:07:29.364: e/androidruntime(1336): @ java.lang.reflect.constructor.constructnative(native method) 05-03 11:07:29.364: e/androidruntime(1336): @ java.lang.reflect.constructor.newinstance(constructor.java:417) 05-03 11:07:29.364: e/androidruntime(1336): @ android.view.layoutinflater.createview(layoutinflater.java:586) 05-03 11:07:29.364: e/androidruntime(1336): ... 23 more 05-03 11:07:29.364: e/androidruntime(1336): caused by: java.lang.nullpointerexception 05-03 11:07:29.364: e/androidruntime(1336): @ com.example.customview.expandableview.setchildview(expandableview.java:48) 05-03 11:07:29.364: e/androidruntime(1336): @ com.example.customview.expandableview.<init>(expandableview.java:41) 05-03 11:07:29.364: e/androidruntime(1336): ... 26 more /////
case 3:-
Comments
Post a Comment