Issue
I have a program project. I have three buttons in the same class (mainpage.java), but one of the buttons doesn't work!
Although I have designed them (the three buttons) in the same form!
My XML:
<Button
android:text="Facebook videos"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:onClick="fb"
android:id="@+id/fbbtn"
android:drawableRight="@drawable/fbico"
android:layout_marginTop="50dp"
android:layout_marginBottom="25dp"/>
<Button
android:text="YouTube videos"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:onClick="gotoyt"
android:id="@+id/ytbtn"
android:drawableRight="@drawable/ytico"
android:layout_marginTop="5dp"
android:layout_marginBottom="25dp"/>
<Button
android:text="others"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:drawableRight="@drawable/allico"
android:onClick="gotoalllinks"
android:id="@+id/othbtn"
android:layout_marginTop="5dp"
android:layout_marginBottom="25dp"/>
And my Java classes:
public void gotoyt(View v) {
ent.putExtra("linktype", "YouTube");
startActivity(ent);
}
public void gotoalllinks(View v) {
ent.putExtra("linktype", "other");
startActivity(ent);
}
public void fbgo(View v) {
ent.putExtra("linktype", "Facebook");
startActivity(ent);
}
When I click on "Facebook videos" button (the first one), my program gets closed!
Solution
You mistyped the callback in your layout, so you need to change the android:onClick="fb"
of your Facebook button to android:onClick="gotoyt"
.
So, change your layout to:
<Button
android:text="YouTube videos"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:onClick="gotoyt"
android:id="@+id/ytbtn"
android:drawableRight="@drawable/ytico"
android:layout_marginTop="5dp"
android:layout_marginBottom="25dp"/>
<Button
android:text="others"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:drawableRight="@drawable/allico"
android:onClick="gotoalllinks"
android:id="@+id/othbtn"
android:layout_marginTop="5dp"
android:layout_marginBottom="25dp"/>
<Button
android:text="Facebook videos"
android:theme="@style/btncar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:padding="6dp"
android:background="@drawable/zee"
android:gravity="center"
android:onClick="fbgo"
android:id="@+id/fbbtn"
android:drawableRight="@drawable/fbico"
android:layout_marginTop="50dp"
android:layout_marginBottom="25dp"/>
Answered By - Zain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.