android fragment cannot setvisibility relativelayout -
i usging fragments, , in activity want show/hide relativelayout(the last: xk1) when touch edittext :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/xmlayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/linearborder" > <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/xsublayout" android:keepscreenon="true" android:orientation="vertical" android:layout_below="@+id/rl_boutton" android:layout_width="fill_parent" android:layout_height="fill_parent" > <edittext android:id="@+id/edittext_code_d" android:layout_width="304dp" android:layout_height="wrap_content" android:layout_below="@+id/rl_boutton" android:layout_centerhorizontal="true" android:background="@drawable/plaquehaut" android:ems="4" android:gravity="center_vertical|center_horizontal" android:inputtype="number" android:maxlength="4" android:text="123" android:textsize="80sp" android:focusableintouchmode="true" /> <edittext android:id="@+id/edittext_code_m" android:layout_width="304dp" android:layout_height="wrap_content" android:layout_alignleft="@+id/edittext_code_d" android:layout_below="@+id/edittext_code_d" android:background="@drawable/plaquebas" android:ems="4" android:gravity="center_vertical|center_horizontal" android:inputtype="number" android:maxlength="4" android:text="1337" android:textsize="80sp" /> </relativelayout> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:id="@+id/xk1" android:layout_height="wrap_content" android:orientation="vertical" android:visibility="gone"> <include android:id="@+id/xkeyboard" layout="@layout/keyboard"> </include> </relativelayout> </relativelayout>
here's code:
public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_rsslist_overview,container, false); seek { mlayout = (relativelayout) view.findviewbyid(r.id.xk1); mklayout = (relativelayout) view.findviewbyid(r.id.xkeyboard); } grab (exception e) { log.w(getclass().getname(), e.tostring()); } met = (edittext) view.findviewbyid(r.id.edittext_code_d); met.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { edittext_onclick(v); } }); met1 = (edittext) view.findviewbyid(r.id.edittext_code_m); met1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { edittext_onclick(v); } }); met.setontouchlistener(this); homecoming view; } public boolean ontouch(view v, motionevent event) { enablekeyboard(); homecoming true; } private void enablekeyboard() { mlayout.setvisibility(relativelayout.visible); mklayout.setvisibility(relativelayout.visible); }
the activity stop when programme run here: mlayout.setvisibility(relativelayout.visible);
how can resolve this?
thx, in advance.
logcat:
02-18 12:06:27.364: i/dalvikvm(1044): wrote stack traces '/data/anr/traces.txt' 02-18 12:06:28.963: d/androidruntime(1044): shutting downwards vm 02-18 12:06:28.963: w/dalvikvm(1044): threadid=1: thread exiting uncaught exception (group=0x409c01f8) 02-18 12:06:29.104: e/androidruntime(1044): fatal exception: main 02-18 12:06:29.104: e/androidruntime(1044): java.lang.nullpointerexception 02-18 12:06:29.104: e/androidruntime(1044): @ fr.app.tutorielfragment.mylistfragment.enablekeyboard(mylistfragment.java:363) 02-18 12:06:29.104: e/androidruntime(1044): @ fr.app.tutorielfragment.mylistfragment.ontouch(mylistfragment.java:240) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.view.dispatchtouchevent(view.java:5536) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1684) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1684) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1684) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1684) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:1957) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:1684) 02-18 12:06:29.104: e/androidruntime(1044): @ com.android.internal.policy.impl.phonewindow$decorview.superdispatchtouchevent(phonewindow.java:1912) 02-18 12:06:29.104: e/androidruntime(1044): @ com.android.internal.policy.impl.phonewindow.superdispatchtouchevent(phonewindow.java:1371) 02-18 12:06:29.104: e/androidruntime(1044): @ android.app.activity.dispatchtouchevent(activity.java:2364) 02-18 12:06:29.104: e/androidruntime(1044): @ com.android.internal.policy.impl.phonewindow$decorview.dispatchtouchevent(phonewindow.java:1860) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.view.dispatchpointerevent(view.java:5721) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewrootimpl.deliverpointerevent(viewrootimpl.java:2890) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2466) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewrootimpl.processinputevents(viewrootimpl.java:845) 02-18 12:06:29.104: e/androidruntime(1044): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2475) 02-18 12:06:29.104: e/androidruntime(1044): @ android.os.handler.dispatchmessage(handler.java:99) 02-18 12:06:29.104: e/androidruntime(1044): @ android.os.looper.loop(looper.java:137) 02-18 12:06:29.104: e/androidruntime(1044): @ android.app.activitythread.main(activitythread.java:4424) 02-18 12:06:29.104: e/androidruntime(1044): @ java.lang.reflect.method.invokenative(native method) 02-18 12:06:29.104: e/androidruntime(1044): @ java.lang.reflect.method.invoke(method.java:511) 02-18 12:06:29.104: e/androidruntime(1044): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 02-18 12:06:29.104: e/androidruntime(1044): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 02-18 12:06:29.104: e/androidruntime(1044): @ dalvik.system.nativestart.main(native method) 02-18 12:06:29.693: i/dalvikvm(1044): threadid=3: reacting signal 3 02-18 12:06:29.726: i/dalvikvm(1044): wrote stack traces '/data/anr/traces.txt' 02-18 12:06:34.654: i/process(1044): sending signal. pid: 1044 sig: 9
you should define next top view: xmlns:android="http://schemas.android.com/apk/res/android" think why nullpointerexception layoutinflater can't find right view throuh hierachy.
android android-layout
No comments:
Post a Comment