1,Create button in xml layout
<Button
android:id="@+id/feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Feedback"
android:textSize="15dp" />
2,In Java Class
Button Myfeedbackbutton=(Button)findViewById (R.id.feedback); (get button id)
Myfeedbackbutton.setOnClickListener(new View.OnClickListener() (Click Listener)
{
public void onClick(View v) {
Intent feedback1= new Intent(android.content.Intent.ACTION_SEND);
feedback1.setType("text/plain");
feedback1.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"Your Email"});
feedback1.putExtra(android.content.Intent.EXTRA_SUBJECT, "Email Title");
startActivity(feedback1);
}
});
Using Buttons in Android apps development
This Tutorial shows how to use Buttons in Android apps development
1,Drag & Drop Button from Eclipse IDE
2,Select Properties and Assign name & Text Size
3,Right Click on button & select Edit ID ,Ex :Button3
4,Link this Button3 to Java by
//Start of Existing code
protected void onCreate(Bundle savedInstanceState) { //Executes when app launched
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //Running Main.xml
//End of Existing code
//Start > Adding Button click event
Button Button3=(Button)findViewById (R.id.Button3);
Button3.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub //Write your Code here
startActivity(new Intent ("com.mani.Convertor.TutorialOne")); //In my case I opened new Class
}
});
//End > Adding Button click event
Subscribe to:
Posts (Atom)