Skip to content Skip to sidebar Skip to footer

Android How To Link Xml With Button?

I know how to screen1.xml to screen2.xml, with onClick method in my .java. But isit possible for me to just redirect to a xml with just ? I mean without anything in .java. Because

Solution 1:

I guess you need onClick on your buttons

 <Button
     android:layout_height="wrap_content"
     android:layout_width="wrap_content"
     android:text="@string/self_destruct"
     android:onClick="selfDestruct" />

then implement the method selfDestruct() in your Activity:

publicvoidselfDestruct(View view) {
     // Kabloey
 }

Solution 2:

This example show how to dynamically create a view and add on main view. For you problem, only replace view for button:

How to dynamically create a view and add on main view in android?

Another alternative, is to use the include tag:

Using "merge" and "include"

Post a Comment for "Android How To Link Xml With Button?"