Practice Mid term Solutions
Originally Posted By: shailbenq
Solution 4 : by Chinmay bhawe, Eugene, Ajinkya amrute and Shailesh Benake
Show the necessary code and describe any interface building activities needed to create a small app (platform of your choice from amongst those covered this semester) with a button on it, which when clicked opens an alert dialog with the words "Cancel Me!" on it. When the user clicks cancel me, the alert goes away.
Android way -
step 1: Go to the layout (say main.xml)
step 2: Add a button to the layout,set its id to say "button1"
step 3:
Set method Attribute as,
[ android:onClick = "clickerMethod"]
now add a method by the name "void clickerMethod"
code:
Code: public void clickerMethod(View v)
{
AlertDialog.Builder bd = new AlertDialog.Builder(this);
bd.setNegativeButton("Cancel Me", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int d){
dialog.cancel();
}
});
AlertDialog confirmation = bd.create();
confirmation.show();
}
I executed the above code on emulator its working fine as mentioned in the question
'''Originally Posted By: shailbenq'''
Solution 4 : by Chinmay bhawe, Eugene, Ajinkya amrute and Shailesh Benake<br><br>Show the necessary code and describe any interface building activities needed to create a small app (platform of your choice from amongst those covered this semester) with a button on it, which when clicked opens an alert dialog with the words "Cancel Me!" on it. When the user clicks cancel me, the alert goes away.<br><br>Android way -<br>step 1: Go to the layout (say main.xml)<br>step 2: Add a button to the layout,set its id to say "button1"<br>step 3:<br> Set method Attribute as,<br> [ android:onClick = "clickerMethod"]<br> now add a method by the name "void clickerMethod"<br>code:<br> Code: public void clickerMethod(View v)<br> { <br> AlertDialog.Builder bd = new AlertDialog.Builder(this);<br> bd.setNegativeButton("Cancel Me", new DialogInterface.OnClickListener(){<br> public void onClick(DialogInterface dialog,int d){<br> dialog.cancel();<br> }<br> });<br> AlertDialog confirmation = bd.create();<br> confirmation.show();<br> }<br><br><br>I executed the above code on emulator its working fine as mentioned in the question<br>