java - button action in fragment -


i have fragment , there textview , button, found solution adding action button inside fragment, must change text in textview. did in way, doesn't work, can check ?

fragment:

public class articlefragment extends fragment {   static public int licznik=0;   public view view;    @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate layout fragment        view = inflater.inflate(r.layout.article_view, container, false);       final textview article2 = (textview)view.findviewbyid(r.id.article);        button menubutton = (button)view.findviewbyid(r.id.button1);         menubutton.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 article2.settext(++licznik);             }         });          return view;     }    @override     public void onstart() {         super.onstart();          textview article = (textview)view.findviewbyid(r.id.article);         article.settext("cos tam");     } 

}

xml of fragment:

    <?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >      <textview         android:id="@+id/article"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/>      <button         android:id="@+id/button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/reso"         android:onclick="action" />    </linearlayout> 

everything okey, during don't click button, application sttoped.

cheers ;d

edit::

   10-06 20:58:18.921: e/trace(828): error opening trace file: no such file or directory (2)     10-06 20:58:19.841: i/choreographer(828): skipped 39 frames!  application may doing work on main thread.     10-06 20:58:19.882: d/gralloc_goldfish(828): emulator without gpu emulation detected.     10-06 20:58:21.931: w/resourcetype(828): no package identifier when getting value resource number 0x00000001     10-06 20:58:21.931: d/androidruntime(828): shutting down vm     10-06 20:58:21.931: w/dalvikvm(828): threadid=1: thread exiting uncaught exception (group=0x40a71930)     10-06 20:58:21.971: e/androidruntime(828): fatal exception: main     10-06 20:58:21.971: e/androidruntime(828): android.content.res.resources$notfoundexception: string resource id #0x1     10-06 20:58:21.971: e/androidruntime(828):  @ android.content.res.resources.gettext(resources.java:230)     10-06 20:58:21.971: e/androidruntime(828):  @ android.widget.textview.settext(textview.java:3769)     10-06 20:58:21.971: e/androidruntime(828):  @ com.example.developer.articlefragment$1.onclick(articlefragment.java:43)     10-06 20:58:21.971: e/androidruntime(828):  @ android.view.view.performclick(view.java:4204)     10-06 20:58:21.971: e/androidruntime(828):  @ android.view.view$performclick.run(view.java:17355)     10-06 20:58:21.971: e/androidruntime(828):  @ android.os.handler.handlecallback(handler.java:725)     10-06 20:58:21.971: e/androidruntime(828):  @ android.os.handler.dispatchmessage(handler.java:92)     10-06 20:58:21.971: e/androidruntime(828):  @ android.os.looper.loop(looper.java:137)     10-06 20:58:21.971: e/androidruntime(828):  @ android.app.activitythread.main(activitythread.java:5041)     10-06 20:58:21.971: e/androidruntime(828):  @ java.lang.reflect.method.invokenative(native method)     10-06 20:58:21.971: e/androidruntime(828):  @ java.lang.reflect.method.invoke(method.java:511)     10-06 20:58:21.971: e/androidruntime(828):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793)     10-06 20:58:21.971: e/androidruntime(828):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560)     10-06 20:58:21.971: e/androidruntime(828):  @ dalvik.system.nativestart.main(native  method) 

i'm guessing problem, eventhough have posted no log dump :

            article2.settext(++licznik); 

to

            article2.settext(string.valueof(++licznik)); 

otherwise looking resource.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -