Wednesday, 6 June 2012

Simple Scrollview Demo



/* This is Simple Scrollview Demo 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" >
<ScrollView
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
       android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">"
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 1"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 2"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 3"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 4"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 5"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 6"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 7"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 8"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 9"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
  <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 16"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 17"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 18"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 19"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textAppearance="?android:attr/textAppearanceMedium"
       android:text="Text 20"
       android:layout_marginTop="10dp"
       android:layout_marginLeft="140dp">      
    </TextView>
    </LinearLayout>
</ScrollView>
</LinearLayout>


ScrollviewDemoActivity.java


package com.scrollviewdemo;

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

public class ScrollviewDemoActivity extends Activity {
    /** Called when the activity is first created. */

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}




Simple Ratingbar Demo




/* This is Simple Ratingbar 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">"

     <RatingBar
        android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1.0"
        android:rating="2.0"/>
   
</LinearLayout>



RatingDemoActivity.java



package com.rating;

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;

public class RatingDemoActivity extends Activity {
RatingBar ratingBar;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        ratingBar = (RatingBar) findViewById(R.id.ratingBar1);
        ratingBar.setOnRatingBarChangeListener(new myListener());
    }
    class myListener implements RatingBar.OnRatingBarChangeListener
    {

        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating,
                boolean fromUser) {
            // TODO Auto-generated method stub
            Toast.makeText(RatingDemoActivity.this, "Rating => "+rating, Toast.LENGTH_SHORT).show();
        }
    }



}

Tuesday, 5 June 2012

Simple Listview Demo



/* This is Simple Listview 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" >
 
    <ListView
        android:id="@+id/lstDemo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>


 ListViewDemoActivity.java



package com.listviewdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewDemoActivity extends Activity {
    /** Called when the activity is first created. */
String[] data = {"Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9","Item10"};
ListView lsDemo;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        lsDemo=(ListView)findViewById(R.id.lstDemo);
        ArrayAdapter<String> lstAdapter = new ArrayAdapter<String>(ListViewDemoActivity.this,android.R.layout.simple_list_item_1, data);
        lsDemo.setAdapter(lstAdapter);
        lsDemo.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(ListViewDemoActivity.this, parent.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show();
}
});
    }
}



Simple Alert Dialogbox Demo



/* This is Simple Alert Dialogbox 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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>


AlertDialogDemoActivity.java

package com.alertdialog;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AlertDialogDemoActivity extends Activity {
Button btn;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn=(Button)findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog.Builder builder = new AlertDialog.Builder(AlertDialogDemoActivity.this);
builder.setTitle("My Dialog");
builder.setMessage("Desc...")
.setPositiveButton("Ok",new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
System.out.println("Ok press");
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
System.out.println("Cancel press");
}
}).show();
}
});
    }
}



Monday, 4 June 2012

Simple Spinner Demo


/* This is Simple Spinner 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" >


    <Spinner
        android:id="@+id/spnDemo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>


 SpinnerDemoActivity.java



package com.spinnerdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class SpinnerDemoActivity extends Activity {
    /** Called when the activity is first created. */
Spinner spnDemo;
String[] data = {"Selet Item","Item 1"};
ArrayAdapter<String> spnAdapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        spnAdapter= new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item,data);
        spnAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnDemo=(Spinner)findViewById(R.id.spnDemo);
        spnDemo.setPrompt("My List");
        spnDemo.setAdapter(spnAdapter);
     
        spnDemo.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
if(arg2!=0)
Toast.makeText(SpinnerDemoActivity.this, arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
});
    }
}




Simple Radio Group & Radio Button Demo


/* This is Simple Radio Group & Radio 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" >

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/rdRed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Red" />

        <RadioButton
            android:id="@+id/rdGreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Green" />

        <RadioButton
            android:id="@+id/rdBlue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Blue" />
    </RadioGroup>

</LinearLayout>

RadioDemoActivity.java


package com.radiodemo;

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

public class RadioDemoActivity extends Activity {
    /** Called when the activity is first created. */
RadioButton rdRed,rdGreen,rdBlue;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        rdRed=(RadioButton)findViewById(R.id.rdRed);
        rdGreen=(RadioButton)findViewById(R.id.rdGreen);
        rdBlue=(RadioButton)findViewById(R.id.rdBlue);
     
        rdRed.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(RadioDemoActivity.this, rdRed.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
     
        rdGreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(RadioDemoActivity.this, rdGreen.getText().toString(), Toast.LENGTH_SHORT).show();
}
});

        rdBlue.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(RadioDemoActivity.this, rdBlue.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
    }
}




Simple Check Box Demo


/* This is First Basic Demo of Check Box 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" >

    <CheckBox android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />
 
<CheckBox android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
   
</LinearLayout>


CheckboxDemoActivity.java


package com.checkbox;

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

public class CheckboxDemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        final CheckBox check_box1 = (CheckBox) findViewById(R.id.cb1);
        final CheckBox check_box2 = (CheckBox) findViewById(R.id.cb2);
        check_box1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
        if(check_box1.isChecked())
        {
        Toast.makeText(CheckboxDemoActivity.this, "I am a male",Toast.LENGTH_SHORT).show();
        }
        }
        });
        check_box2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            if(check_box2.isChecked())
            {
                Toast.makeText(CheckboxDemoActivity.this, "I am a female",Toast.LENGTH_SHORT).show();
            }
            }
            });
    }
}





Twitter Delicious Facebook Digg Stumbleupon Favorites More

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