Same xml load on multiple button click in Android -
i have multiple button in main activity, , on every button click same xml loaded "test.xml" dynamic data. "test.xml" loaded on every click contain 5 more buttons , every click of "test.xml" buttons again want load same xml,i.e, "test.xml" different data. how acheive task.
main.xml is-
<relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/idc_leftlayout" > <button android:id="@+id/idc_game1" android:layout_width="120dp" android:layout_height="40dp" android:background="@drawable/g1" android:layout_margintop="20dp" android:onclick="stratgame1" /> <button android:id="@+id/idc_game2" android:layout_width="120dp" android:layout_height="40dp" android:background="@drawable/g2" android:layout_below="@id/idc_game1" android:layout_margintop="10dp" android:onclick="stratgame2"/> <button android:id="@+id/idc_game3" android:layout_width="120dp" android:layout_height="40dp" android:background="@drawable/g3" android:layout_below="@id/idc_game2" android:layout_margintop="10dp" android:onclick="stratgame3"/> <button android:id="@+id/idc_game4" android:layout_width="120dp" android:layout_height="40dp" android:background="@drawable/g4" android:layout_below="@id/idc_game3" android:layout_margintop="10dp" android:onclick="stratgame4" /> <button android:id="@+id/idc_game5" android:layout_width="120dp" android:layout_height="40dp" android:background="@drawable/g5" android:layout_below="@id/idc_game4" android:layout_margintop="10dp" android:onclick="stratgame5" /> </relativelayout>
test.xml is
<button android:id="@+id/idc_questionoption1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_marginright="36dp" android:layout_toleftof="@+id/idc_questionoption2" android:background="@drawable/lev1ques1img3" /> <button android:id="@+id/idc_questionoption2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_marginright="40dp" android:layout_toleftof="@+id/idc_questionoption3" android:background="@drawable/lev1ques1img4" /> <button android:id="@+id/idc_questionoption3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_marginright="79dp" android:background="@drawable/lev1ques1img5" /> <button android:id="@+id/idc_question" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/idc_questionoption1" android:layout_alignparentleft="true" android:background="@drawable/lev1ques1img2" />
please me same.
any appreciated. in advance.
you should use multiple activities
main activity
... button button1 = (button) findviewbyid(r.id.your_button_1_id); button button2 = (button) findviewbyid(r.id.your_button_2_id); ... button1.setonclicklistener(this); button2.setonclicklistener(this); ... public void onclick(view v) { if(v.getid() == r.id.your_button_1_id) { intent = new intent(this, youractivity.class); i.putextra("calledfrombutton", 1); startactivity(i,1); } else if(v.getid() == r.id.your_button_2_id) { intent = new intent(this, testactivity.class); i.putextra("calledfrombutton", 2); startactivity(i,1); } ... } ...
test activity
... int calledfrombutton = getintent().getintextra("calledfrombutton"); ...
now have in variable calledfrombutton number button, clicked.
Comments
Post a Comment