Tips N TRIKS: button click
Showing posts with label button click. Show all posts
Showing posts with label button click. Show all posts

Sunday, 14 September 2014

Android 02

September 14, 2014 0
Android 02

Today we will learn to display message with new things. for example you will write your name in edittext you will het hie name...
  •  to make this thing we need a..
    • Button for click
    • edittext to write your name
    • toast for display message

About application:
  • this simple app contain.when you write your name on edittext it will display message with hie.
Names :
  • java file::MainActivity.java
  • xml file::activity_main.xml

STEP 1:: 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" >

    <EditText
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="42dp"
        android:ems="10" />

    <Button
        android:id="@+id/bnt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txt1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="38dp"
        android:text="clickme" />

</RelativeLayout>

STEP 2:: MainActivity.java


package com.example.athome;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener{
Button bnt1;
EditText txt1;
String str;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt1=(EditText) findViewById(R.id.txt1);
        bnt1=(Button)findViewById(R.id.bnt1);
        str=txt1.getText().toString();
        bnt1.setOnClickListener(this);
        
        
    } 


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId()==R.id.bnt1) 
{
Toast.makeText(this,"hie "+txt1.getText(), Toast.LENGTH_LONG).show();
}

}
    
}


Here ends our 2 lesson.if you like then comment it. 

Saturday, 13 September 2014

Android 01

September 13, 2014 0
Android 01
             How to make your first application on android

  • Thinks you required :
    1. sdk
    2. eclips
IF you r complete setup you can develop first application:
  • this appellation contain 
    • using of java
    • using of xml file
About application:
  • this simple app contain.when you click on button message is displayed as given in below picture.


Names :
  • java file::MainActivity.java
  • xml file::activity_main.xml
STEP 1:: 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" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="While click message displayes.." />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="15dp"
        android:text="Button" />

</RelativeLayout>

STEP 2:: MainActivity.java


package com.example.myfirstapp;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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 b1;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(this);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(this, "I am button which you clicked", Toast.LENGTH_LONG).show();
}

}



Here ends our 1 lesson.if you like then comment it.