Friday, 23 September 2016

First Android Program

Firstly Create new Project and add these lines in MainActivity.java & activity_main.xml

activity_main.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: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.sahil.inmobi.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Android Studio Tutorial"
        android:id="@+id/karantips"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="First Activity"
        android:id="@+id/first"
        android:layout_below="@+id/karantips"
        android:onClick="Safal"/>
</RelativeLayout>

MainActivity.java

package com.example.sahil.inmobi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
TextView textView; // First Android Project by www.karantips.com
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView=(TextView)findViewById(R.id.karantips);
    }
    public void Safal(View view)
    {
String message="Welcome to Karantips and First Android Project Tutorial";
        textView.setText(message);
    }
}   //First Android Project By www.karantips.com



No comments:

Post a Comment