Android
Project: Toast With OnClick (For Beginers):
Android
Project: Toast With OnClick (For Beginers):
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="100dp"
android:layout_marginTop="96dp"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="@+id/etTestBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:onClick="test"
android:layout_marginTop="20dp"
android:text="Test" />
</RelativeLayout>
MainActivity.java
package com.sattar.uicontroldemo;
import
android.app.Activity;
import android.os.Bundle;
import android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Button
btnTest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnTest=(Button)
findViewById(R.id.etTestBtn);
btnTest.setOnClickListener(this);
}
public void test(View v) {
Toast.makeText(getApplicationContext(),
"test
button clicked",
Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(),
"test
button clicked",
Toast.LENGTH_LONG).show();
}
}
No comments:
Post a Comment