We-Pad: Could it be Android's iPad Killer ?

Recently a german based company showed a new product: We-Pad (instead of iPad).
it's the same concept of iPad but runs on Android OS and Supports Flash.

see more details here

Reactions: 

Android Date and Time Controls

The Date-Time Controls in Android enable the user to pick date and time values and store them anywhere.
The date and time controls include:
1. DatePicker
2. Time Picker.
3. DatePickerDialog.
4. TimePickerDialog.
5. AnalogClock.
6. DigitalClock.
7. chronometer

DatePicker:

The DatePicker control enables the user to select a value of date only.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    />
    <DatePicker
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/datePick"
    />
    <Button
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/btn"
    android:text="Select Date"
    />
</LinearLayout>


final DatePicker dp=(DatePicker)findViewById(R.id.datePick);
        Button btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(new OnClickListener()
        {

   public void onClick(View arg0) {
    // TODO Auto-generated method stub
   
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText("You selected "+dp.getDayOfMonth()+"/"+(dp.getMonth()+1)+"/"+dp.getYear());
   }
         
        }
        
        );

Notice that we add 1 to the value of DatePicker.getMonth() because the months range is from 0 to 11.

If you want to set an initial selected date for the DatePicker you can use:
DatePicker.init(year, monthOfYear, dayOfMonth, onDateChangedListener);

If you want to capture the date as the date changes in the control you can make the activity implements the OnDateChangedListener interface and implements the onDateChanged method
Calendar cal=Calendar.getInstance(Locale.ENGLISH);
        dp.init(cal.getTime().getYear()+1900, cal.getTime().getMonth(), cal.getTime().getDay(), this);

then

public void onDateChanged(DatePicker view, int year, int monthOfYear,
   int dayOfMonth) {
  // TODO Auto-generated method stub
  TextView txt=(TextView)findViewById(R.id.txt);
  txt.setText("You selected "+view.getDayOfMonth()+"/"+(view.getMonth()+1)+"/"+view.getYear());
 }


TimePicker:
TimePicker is like DatePicker but it displays time instead of date, here’s how it looks like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    />
    <TimePicker
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/TimePick"
    />
    <Button
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/btn"
    android:text="Select Date"
    />
</LinearLayout>


final TimePicker tp=(TimePicker)findViewById(R.id.TimePick);
        Button btn=(Button)findViewById(R.id.btn);
        btn.setOnClickListener(new OnClickListener()
        {

   public void onClick(View arg0) {
    // TODO Auto-generated method stub
   
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText("You selected "+tp.getCurrentHour()+":"+tp.getCurrentMinute());

Notice that by default the time picker displays the time in AM/PM format. If you want it to display time in 24-hours format you can use
TimePicker.setIs24HourView(boolen is24HourView);
If you want to initialize the timepicker with a certain time you can use the methods:

TimePicker.setCurrentHour(int Hour);
TimePicker.setCurrentMinute(int Minute);

You can implement the OnTimeChangedListener so that you capture any change in the time picker:
final TimePicker tp=(TimePicker)findViewById(R.id.TimePick);
        tp.setCurrentHour(10);
        tp.setCurrentMinute(45);
        
        tp.setOnTimeChangedListener(new OnTimeChangedListener()
        {

   public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText("You selected "+arg0.getCurrentHour()+":"+arg0.getCurrentMinute());
   }
         
        }
        );

We checked so far the DatePicker and TimePicker widgets, but they take big space on the screen so Android provides similar controls but with different look: the DatePickerDialog and TimePickerDialog.

These widgets act the same as DatePicker and TimePicker but the appear as dialogs or popups instead of occupying a space on the screen

DatePickerDialog
DatePickerDialog is not a View, that you can’t define it in the xml layout file.
Instead you declare it from code with the following two constructors:
DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth);
DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth);

You can use it like this:
public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn=(Button)findViewById(R.id.btn);

final OnDateSetListener odsl=new OnDateSetListener()
        {

   public void onDateSet(DatePicker arg0, int year, int month, int dayOfMonth) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText("The date is "+dayOfMonth+"/"+month+"/"+year);
   }
         
        };

btn.setOnClickListener(new OnClickListener()
        {

   public void onClick(View arg0) {
    // TODO Auto-generated method stub
   
    
    Calendar cal=Calendar.getInstance();
    DatePickerDialog datePickDiag=new DatePickerDialog(DateTimeControls.this,odsl,cal.get(Calendar.YEAR),cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH));
    datePickDiag.show();
   }
         
        }
        
        );

}

To take an action when the date is set you define an OnDateSelectedListner and implement the onDateSet method

TimePickerDialog

DatePickerDialog is similar to DatePickerDialog but used for setting time.
The constructors for TimePickerDialog are:
TimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView);

TimePickerDialog(Context context, int theme, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView);


You can use it like this:
public void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn=(Button)findViewById(R.id.btn);
}

final OnTimeSetListener otsl=new OnTimeSetListener()
        {

   public void onTimeSet(TimePicker arg0, int hourOfDay, int minute) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText("The time is "+hourOfDay+":"+minute);
   }
        };

btn.setOnClickListener(new OnClickListener()
        {

   public void onClick(View arg0) {
    // TODO Auto-generated method stub
   
    
    Calendar cal=Calendar.getInstance();
    TimePickerDialog timePickDiag=new TimePickerDialog(DateTimeControls.this,otsl,cal.get(Calendar.HOUR_OF_DAY),cal.get(Calendar.MINUTE),true);
    timePickDiag.show();
   }
         
        }
        
        );




AnalogClock

If you want to display time as in a clock you can use the AnalogClock widget. It just displays the time with no ability to edit the time.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    />
    
    <AnalogClock  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/clock"
    />
    
    
</LinearLayout>






DigitalClock
Same as AnalogClock but displays a digital clock
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    />
    
    <DigitalClock 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/digitalClock"
    />
    
    
</LinearLayout>




ChronoMeter:

The ChronoMeter acts like a timer. It has a starting point and an endpoint and you can calculate the time elapsed between these two points.

Reactions: 

Intel Running Android on Atom Chips

Hi all
Check this article found on Technorati.

I believe it's a step towards the right direction for Android.

Reactions: 

Selection Controls 3: CheckBox and RadioButton

CheckBox:

The check box has two states: Checked and UnChecked. It inherits from TextView so it has all of its properties:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:id="@+id/txt"
    />
    <CheckBox
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:id="@+id/Chk"
    android:text="This is a check box"
    android:checked="false"
    
    />
</LinearLayout>



and to handle the check/uncheck event:
CheckBox chk=(CheckBox)findViewById(R.id.Chk);
        chk.setOnCheckedChangeListener(new OnCheckedChangeListener()
        {

   public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
    TextView txt=(TextView)findViewById(R.id.txt);
    if (arg1)
     txt.setText("checked");
    else
     txt.setText("Unchecked");
    
   }
         
        }
        );


RadioButton:
Android provides Radio button control. You create a RadioGroup and add RadioButtons inside it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
    android:id="@+id/txt"
    android:layout_width="fill_parent"
android:layout_height="fill_parent"
    />
   <RadioGroup
   android:id="@+id/group"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Radio Group"
>
<RadioButton android:id="@+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item1"
android:checked="true"
 />
<RadioButton android:id="@+id/item2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item2" />
<RadioButton android:id="@+id/item3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item3" />
</RadioGroup>
</LinearLayout>




You can get the checked item from code like this:
RadioGroup rg=(RadioGroup)findViewById(R.id.group);
        rg.setOnCheckedChangeListener(new android.widget.RadioGroup.OnCheckedChangeListener()
        {

   public void onCheckedChanged(RadioGroup arg0, int arg1) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    RadioButton rb=(RadioButton)findViewById(arg1);
    txt.setText("You selected "+rb.getText());
    
   }
         
        }
        );

Reactions: 

Selection Controls 2: The spinner Control

The spinner controls is similar to the ComboBox in C#. it displays a list to select from in a popup window so ot may become a better choice over ListView if you want to save space.

It works in a similar way to that of the the listView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Spinner
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:id="@+id/Spinner"
    />
</LinearLayout>




when you click on the spinner it popups like this:
To handle the selected item you can use do it like this:
final String [] items=new String[]{"Item1","Item2","Item3","Item4"};
        ArrayAdapter ad=new ArrayAdapter(this,android.R.layout.simple_spinner_item,items);
        ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        Spinner spin=(Spinner)findViewById(R.id.Spinner);
        spin.setAdapter(ad);
        spin.setOnItemSelectedListener(new OnItemSelectedListener()
        {

   public void onItemSelected(AdapterView arg0, View arg1,
     int arg2, long arg3) {
    TextView txt=(TextView)findViewById(R.id.txt);
    TextView temp=(TextView)arg1;
    txt.setText(temp.getText());
    
   }

   public void onNothingSelected(AdapterView arg0) {
    // TODO Auto-generated method stub
    
   }
        
        });

The above code displays the selected item text in the textview.

The parameters of the OnItemClick method are:


Arg0:the Spinner, notice that it is of type AdapterView.

Arg1: the view that represents the selected item, in this example it will be a TextView

Arg2: the position of the selected item.

Arg3: the id of the selected item.

and that's it for the Spinner Control.

Reactions: 

Android Selection Controls

Android offers selection Controls like


1. List View.

2. Spinner

3. Check box

4. Radio Button

The List View:


ListView represents a list of items that can be selected. It is similar to the ListBox in C#.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    />
    <ListView
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:id="@+id/List"
    />
</LinearLayout>



To populate the list and handle the ItemClick event we can do it like this :
final String [] items=new String[]{"Item1","Item2","Item3","Item4"};
        ArrayAdapter ad=new ArrayAdapter(this,android.R.layout.simple_list_item_1,items);
        list=(ListView)findViewById(R.id.List);
        list.setAdapter(ad);
list.setOnItemClickListener(new OnItemClickListener()
        {

   public void onItemClick(AdapterView arg0, View arg1, int arg2,
     long arg3) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    txt.setText(list.getItemAtPosition(arg2).toString());
    
    
   }
         
        }
        );

The above code displays the selected item text in the textview:
The parameters of the OnItemClick method are:


Arg0:the listview, notice that it is of type AdapterView.

Arg1: the view that represents the selected item, in this example it will be a TextView

Arg2: the position of the selected item.

Arg3: the id of the selected item.

When creating the adapter you can specify the layout of the list by using simple_list_item_1 to display a simple list or by using


simple_list_item_single_choice to display radio buttons for single selection

Or by using simple_list_item_multiple_choice to display check boxes for multiple selection
You can set the choice mode of the list by using setchoicemode() method:
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        final String [] items=new String[]{"Item1","Item2","Item3","Item4"};
        ArrayAdapter ad=new ArrayAdapter(this,android.R.layout.simple_list_item_multiple_choice,items);
        setListAdapter(ad);
      ListView list=getListView();
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        
    }

Now suppose you want to change the text of the an item when it is clicked, you can do it like this:
list.setOnItemClickListener(new OnItemClickListener()
        {

   public void onItemClick(AdapterView arg0, View arg1, int arg2,
     long arg3) {
    // TODO Auto-generated method stub
    TextView txt=(TextView)findViewById(R.id.txt);
    items[arg2]="changed";
    list.setAdapter(new ArrayAdapter(ListControls.this,android.R.layout.simple_list_item_1,items));
    
   }
         
        }
        );

Or a more neat way:
list.setOnItemClickListener(new OnItemClickListener()
        {

   public void onItemClick(AdapterView arg0, View arg1, int arg2,
     long arg3) {
    // TODO Auto-generated method stub
    TextView temp=(TextView)arg1;
    temp.setText("changed 2");
   }
         
        }
        );

See that you actually change the value of the string array item at the selected position then bind the listview with the adapter again. Or you capture the View object and do what you want.



If the activity will contain just one listview you can create an activity that extends list view. In this case you don’t have to specify a layout as a listview will fill the screen.
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                final String [] items=new String[]{"Item1","Item2","Item3","Item4"};
        ArrayAdapter ad=new ArrayAdapter(this,android.R.layout.simple_list_item_1,items);
        setListAdapter(ad);


If you want to reference or customize this listview then you can define it in the layouts xml fine by assigning it the id “android:id/list” so that the activity knows which listView is the main list for the activity .

This example shows a listview and a textview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/txt"
    android:text="List View Demo"
    />
    
    <ListView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    />
</LinearLayout>



Now if you want to customize the ui of each row of the listview you define two layouts files: the first has the layout of the activity and the other has layout of each row in the listview

Reactions: