Tuesday 29 November 2016

learn how to set a clicklistener on a button in android

As we want to perform an event of click listener on a button so first of all you should declare a widget of button in your xml file such as
name as ist_activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/ist_activity"
 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="com.stck.fun.contactsofvipsIstActivity">
    <Button 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/btn1"
 android:text="Hello World!" 
/>
</RelativeLayout>


then you should go to your java file.and your java file should be like this

named as IstJava



package com.stck.fun.contactsofvips;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class IstActivityextends AppCompatActivity  {
    Button btn1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ist_activity);
        btn1=(Button) findViewById(R.id.btn1);

    btn1.setOnClickListener(new View.onClickListener){

   pulic void onClick(View v)
{
////perform your desired work
});
}
}



Should Mention tour activity name in android studio's xml file
mine is following






<?xml version="1.0" encoding="utf-8"?><manifest 
xmlns:android="http://schemas.android.com/apk/res/android"
package="contctsofvips.fun.stack.com.myapp">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".IstActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
        </activity>
    </application>

</manifest>



























        

Monday 28 November 2016

How To Place A button Inside a Android Studio Project



My XML File is following
named as activity_asad_xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_asad__class"
    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="com.example.asad.se.Asad_Class">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:id="@+id/btn"
        />
</RelativeLayout>








My Java File is following
named as Asad_Class

package com.example.asad.se;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;

public class Asad_Class extends AppCompatActivity {
    Button btn1;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_asad__class);
        btn1=(Button) findViewById(R.id.btn);
        
    }
}


My Manifest File Is Following





<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.asad.se">
    <application   
     android:allowBackup="true"  
      android:icon="@mipmap/ic_launcher" 
       android:label="@string/app_name"
        android:supportsRtl="true"   
        android:theme="@style/AppTheme">
        <activity android:name=".Asad_Class">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

This is the simple android application for the declaration of a button.

I hope you will like this and don't forget to like and subscribe








Sunday 27 November 2016

How To Make My First Android Project

Open Your Android Studio .You have Following View  
                                                             
After This Click On Start A new Android Studio Project Then You Have Follwing View
After This Write Your Application Name such As mt application And then Click Go to Next

 
Press Next
Then Write Your Activities Names Which shoud be customized according to you will
Then Creating project ang gradle build remain cool and calm hust wait
And Here Is YOUR jAVA file name MainActivity
Your Xml FILE IS like THAT
After THIS rUN YOU PROJECT .hELLO WORLD WILL be the FIRST OUTPUT