Wednesday, 15 February 2012

Simple Listner Demo


/* This is Simple Listner Demo of Android */

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

ListnerDemoActivity.java

package com.listnerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class ListnerDemoActivity extends Activity {
    /** Called when the activity is first created. */
    TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        tv=(TextView)findViewById(R.id.textView1);
        tv.setOnClickListener(new OnClickListener() {
           
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(ListnerDemoActivity.this, "Text Change", Toast.LENGTH_SHORT).show();
                tv.setText("Wiki");
            }
        });
    }
}



Tuesday, 14 February 2012

Simple Edit Text Demo

/* This is Simple Edit Text Demo of Android */

main.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal" >

    <EditText
        android:id="@+id/edtMsg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/tvViewMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/btnClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me" />

</LinearLayout>


 EditTextDemoActivity.java

 package com.edittextdemo;

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

public class EditTextDemoActivity extends Activity {
    /** Called when the activity is first created. */
    EditText edtMsg;
    TextView tvViewMsg;
    Button btnClick;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        edtMsg=(EditText)findViewById(R.id.edtMsg);
        tvViewMsg=(TextView)findViewById(R.id.tvViewMsg);
        tvViewMsg.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                TextView tempTv = (TextView)v;
                tempTv.setText(edtMsg.getText());
            }
        });
        btnClick=(Button)findViewById(R.id.btnClick);
        btnClick.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tvViewMsg.setText(edtMsg.getText());
            }
        });
    }
}



Saturday, 11 February 2012

Simple Button Demo

/* This is Simple Button Demo of Android */

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center" >

    <Button
        android:id="@+id/btnMyClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me" />
   
</LinearLayout>


ButtonDemoActivity.java


package com.buttondemo;

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 ButtonDemoActivity extends Activity {
    /** Called when the activity is first created. */
    Button btnMyClick;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        btnMyClick=(Button)findViewById(R.id.btnMyClick);
        btnMyClick.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(ButtonDemoActivity.this, "My Button is Pressed", Toast.LENGTH_LONG).show();
            }
        });
    }
}


Friday, 10 February 2012

Android First Demo

/* This is First Basic Demo of Android */

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center" >

    <TextView
        android:id="@+id/tvDemo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

FirstDemoActivity.java

 package com.firstdemo;

import android.app.Activity;
import android.os.Bundle;

public class FirstDemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Host