Thursday, July 12, 2012

Display Storing Items in strings.xml file using ListView



Click Here to download source code

Package Name  :   selva.list

Project  Name   :   ListView1

Version             :   1.5 ( Supports 1.5 and above Versions)

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" />

</LinearLayout>


strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, ListView1Activity!</string>
    <string name="app_name">ListView1</string>
  <string-array name="Fruits">
    <item>Apple</item>
    <item>Banana</item>
    <item>Orange</item>
    <item>Mango</item>
    <item>Grapes</item>
    <item>Pine Apple</item>
    <item>Jack Fruit</item>
    <item>Strawberry</item>
    <item>Cucumber</item>
    <item>Pumpkin</item>
  </string-array>
</resources>


ListView1Activity.java

package selva.list;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListView1Activity extends ListActivity {
    /** Called when the activity is first created. */
   
    String Fruits[];
    @Override
public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        ListView lstView = getListView();
        //lstView.setChoiceMode(0); //CHOICE_MODE_NONE
        //lstView.setChoiceMode(1); //CHOICE_MODE_SINGLE
        lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
        lstView.setTextFilterEnabled(true);
        Fruits=getResources().getStringArray(R.array.Fruits);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, Fruits));
    }
public void onListItemClick(ListView parent, View v, int position, long id)
    {
    parent.setItemChecked(position, parent.isItemChecked(position));
    Toast.makeText(this,"You have selected " + Fruits[position],Toast.LENGTH_SHORT).show();
    }

}


OUTPUT: 












































Click Here to download source code


Customizing The ListView In Android



Click Here To Download Source Code

Package Name  :  selva.list

Project Name    :  Cust_ListView

Version             :  1.5 (Supports 1.5 and above versions)

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" />

</LinearLayout>


 Cust_ListviewActivity.java



package selva.list;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class Cust_ListviewActivity extends ListActivity {
    String[] Fruits = {
            "Apple",
            "Banana",
            "Orange",
            "Mango",
            "Grapes",
            "Jack Fruit",
            "Strawberry",
            "cucumber",
            "pumpkin"
        };
   
    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        ListView lstView = getListView();
        //lstView.setChoiceMode(0); //CHOICE_MODE_NONE
        //lstView.setChoiceMode(1); //CHOICE_MODE_SINGLE
        lstView.setChoiceMode(2); //CHOICE_MODE_MULTIPLE
        lstView.setTextFilterEnabled(true);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_checked, Fruits));
// note : You will get pop-up menu when type R . layout .          
//Then select your option. It will display items with different customization
    }
public void onListItemClick(ListView parent, View v, int position, long id)
    {
    parent.setItemChecked(position, parent.isItemChecked(position));
    Toast.makeText(this,"You have selected " + Fruits[position],Toast.LENGTH_SHORT).show();
    }
}






OUTPUT:

 






















































































Click Here To Download Source Code 


ListView in Android



Click Here to download source code

Package Name   :  selva.list

Project Name     :  ListView 

Version              :  1.5 ( Supports 1.5 and above versions)

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" />

</LinearLayout>




ListViewActivity.java


package selva.list;

import android.os.Bundle;
import android.app.ListActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ListViewActivity extends ListActivity
{
    String[] Fruits = {
            "Apple",
            "Banana",
            "Orange",
            "Mango",
            "Grapes",
            "Jack Fruit",
            "Strawberry",
            "cucumber",
            "pumpkin"
        };
   
    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        setListAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_1, Fruits));
    }
public void onListItemClick(ListView parent, View v, int position, long id)
    {
    Toast.makeText(this,"You have selected " + Fruits[position],Toast.LENGTH_SHORT).show();
    }
}




OUTPUT : 











































Click item   "Apple"



































































































































Click Here to download source code


Wednesday, July 11, 2012

DatePickerDialog in Android



Click Here to Download source code 
 

Package Name    :   selva.datepicker 

Project Name      :   DatePickerDialog

Version               :   1.5 (Supports 1.5 and above versions)

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="ShowDatepickerDialog" />

</LinearLayout>



DatePickerDialogActivity.java



package selva.datepicker;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
import android.app.DatePickerDialog;
import java.util.Calendar;

public class DatePickerDialogActivity extends Activity
{
    int yr, month, day;
    static final int DATE_DIALOG_ID = 1;
    DatePicker datePicker;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
      
       
        Button btnOpen = (Button) findViewById(R.id.button1);
       
        btnOpen.setOnClickListener(new View.OnClickListener()
        {
        public void onClick(View v)
        {
      
             Calendar today = Calendar.getInstance();
             yr = today.get(Calendar.YEAR);
             month = today.get(Calendar.MONTH);
             day = today.get(Calendar.DAY_OF_MONTH);
             showDialog(DATE_DIALOG_ID);
           
        }
        });
       
    }
   
    @Override
    protected Dialog onCreateDialog(int id)
    {
        switch (id)
        {
  
        case DATE_DIALOG_ID:
            return new DatePickerDialog(this, mDateSetListener, yr, month, day);
        }
    return null;
    }
   
    private DatePickerDialog.OnDateSetListener mDateSetListener =
    new DatePickerDialog.OnDateSetListener()
    {
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
    {
        yr = year;
    month = monthOfYear;
    day = dayOfMonth;
    Toast.makeText(getBaseContext(), "You have selected :" + (month + 1) + "/" + 
              day+ "/" + year,Toast.LENGTH_SHORT).show();
    }
    };
}



OUTPUT: 
























Click ShowDatepickerDialog button 






































select date and click set button 











































 Click Here to Download source code



DatePicker in Android



Click Here To Download Source Code

Package Name   :   selva.datepicker

Project Name     :  DatePicker

Version              :  1.5 (Supports  1.5 and above versions)


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" />

    <DatePicker
        android:id="@+id/datePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

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

</LinearLayout>


DatePickerActivity.java


 package selva.datepicker;

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

public class DatePickerActivity extends Activity {
  
    DatePicker datePicker;
  
      
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        datePicker = (DatePicker) findViewById(R.id.datePicker1);
      
        Button btnOpen = (Button) findViewById(R.id.button1);
      
        btnOpen.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                Toast.makeText(getBaseContext(),"Date selected:" + datePicker.getMonth() +
                        "/" + datePicker.getDayOfMonth() +
                        "/" + datePicker.getYear()  ,Toast.LENGTH_SHORT).show();
        }
        });
      
      
      
    }
}


 OUTPUT:




























click GetDate Button










































Click Here To Download Source Code


TimePickerDialog in Android



Click Here to download source code 

Package Name  :  selva.timepicker

Project Name    :  TimePickerDialog

Version             :  1.5 ( Support 1.5 and above versions) 



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="ShowTimepickerDialog" />

</LinearLayout>



 TimePickerDialogActivity.java



package selva.timepicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
import android.app.Dialog;
import android.app.TimePickerDialog;
public class TimePickerDialogActivity extends Activity
{
   
    int hour, minute;
    static final int TIME_DIALOG_ID = 0;
    TimePicker timePicker;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
   
   
        Button btnOpen=(Button) findViewById(R.id.button1);
      
        btnOpen.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                showDialog(TIME_DIALOG_ID);
                }
        });
    }
   
@Override
protected Dialog onCreateDialog(int id)
{
    switch (id)
    {
    case TIME_DIALOG_ID:
        return new TimePickerDialog(
                this, mTimeSetListener, hour, minute, false);
    }
    return null;
}
private TimePickerDialog.OnTimeSetListener mTimeSetListener =new TimePickerDialog.OnTimeSetListener()
{
    public void onTimeSet(TimePicker view, int hourOfDay, int minuteOfHour)
    {
        hour = hourOfDay;
        minute = minuteOfHour;
        Toast.makeText(getBaseContext(),"You have selected : " + hour + ":" + minute,Toast.LENGTH_SHORT).show();
    }
};
}

 OUTPUT:

























ClickTimepickerDialog







































select time and click set button















































 Click Here to download source code


TimePicker in Android



Click Here to download source code

Package Name  :  selva.timepicker

Project Name   :  TimePicker

Version            :   1.5 ( Supports 1.5 and above versions)


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="TimePicker" />

    <TimePicker
        android:id="@+id/timePicker1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


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

</LinearLayout>


TimePickerActivity.java


package selva.datepicker;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
import android.widget.Toast;
public class TimePickerActivity extends Activity

{
TimePicker timePicker;
/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        timePicker = (TimePicker) findViewById(R.id.timePicker1);
        timePicker.setIs24HourView(false);
   
        //---Button view---
        Button btnOpen = (Button) findViewById(R.id.button1);
        btnOpen.setOnClickListener(new View.OnClickListener()
        {
   
            public void onClick(View v)
            {
           Toast.makeText(getBaseContext(),"Time selected:"  
                                      +timePicker.getCurrentHour()+":"
                + timePicker.getCurrentMinute(),Toast.LENGTH_SHORT).show();
            }
        });
    }

OUTPUT:






























click get Time









































Click Here to download source code