Category Archives: Technology

TabWidget in Android UI Control

TabWidget is an Android Control which represents each page in the parents tab collection.

the container object for this widget is tab host, When the user selects a tab, this object sent a message to the parent container(tab host), to tell is to switch the displayed page. The container tab host is used to add labels, add call back handlers, and manage call backs.

Android tab host provides a nice way to present multiple things on a single screen, in order to use tabs we have to set two things to the tab:

1) Tab Indicator : text to show on tab, done by “setIndicator(“Tab Name”);”

2) Tab Content : This is used to set the activity that will be opened when the user selects/clicks a particular tab.

this is set by “setContent(“activity object”);”

TabWidget

Activity_Main.xml :

<?xml version=”1.0″ encoding=”utf-8″?>

<TabHost xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:id=”@android:id/tabhost”>

<LinearLayout android:id=”@+id/LinearLayout01″
android:orientation=”vertical”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>

<TabWidget android:id=”@android:id/tabs”
android:layout_height=”wrap_content”
android:layout_width=”fill_parent”>
</TabWidget>

<FrameLayout android:id=”@android:id/tabcontent”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>
</FrameLayout>

</LinearLayout>

</TabHost>

Screen1.xml :

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/LinearLayout01″
android:background=”#FFFF0000″
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>

<Button android:id=”@+id/btnScreen1″
android:layout_width=”150dip”
android:layout_height=”40dip”
android:text=”First Screen” />

</RelativeLayout>

Screen2.xml :

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/LinearLayout02″
android:background=”#FF00FF00″
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>

<Button android:id=”@+id/btnScreen2″
android:layout_width=”150dip”
android:layout_height=”40dip”
android:text=”Second Screen” />

</RelativeLayout>

Screen3.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/LinearLayout02″
android:background=”#FF0000FF”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>

<Button android:id=”@+id/btnScreen3″
android:layout_width=”150dip”
android:layout_height=”40dip”
android:text=”Third Screen” />

</RelativeLayout>

Screen4.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/LinearLayout02″
android:background=”#FFbbbbbb”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”>

<Button android:id=”@+id/btnScreen4″
android:layout_width=”150dip”
android:layout_height=”40dip”
android:text=”fourth Screen” />

</RelativeLayout>

Main_Actvity.java :


package com.example.tabwidget;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class MainActivity extends TabActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

// create the TabHost that will contain the Tabs
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

TabSpec tab1 = tabHost.newTabSpec(“First Tab”);
TabSpec tab2 = tabHost.newTabSpec(“Second Tab”);
TabSpec tab3 = tabHost.newTabSpec(“Third tab”);
TabSpec tab4 = tabHost.newTabSpec(“Fourth tab”);

// Set the Tab name and Activity
// that will be opened when particular Tab will be selected

tab1.setIndicator(“”, getResources().getDrawable(R.drawable.ic_launcher));
tab1.setContent(new Intent(this,Tab1Activity.class));

tab2.setIndicator(“”, getResources().getDrawable(R.drawable.ic_launcher));
tab2.setContent(new Intent(this,Tab2Activity.class));

tab3.setIndicator(“”, getResources().getDrawable(R.drawable.ic_launcher));
tab3.setContent(new Intent(this,Tab3Activity.class));

tab4.setIndicator(“”, getResources().getDrawable(R.drawable.ic_launcher));
tab4.setContent(new Intent(this,Tab4Activity.class));

/** Add the tabs to the TabHost to display. */
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
tabHost.addTab(tab4);

}
}

 

Tab1_Activity.java :

package com.example.tabwidget;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;

public class Tab1Activity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
}
}

 

Tab2_Actvity.java :

package com.example.tabwidget;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;

public class Tab2Activity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
}
}

 

Tab3Activity.java :

package com.example.tabwidget;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class Tab3Activity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
setContentView(R.layout.screen3);
}
}

 

Tab4Actvity.java :

package com.example.tabwidget;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class Tab4Activity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

super.onCreate(savedInstanceState);
setContentView(R.layout.screen4);
}
}

SeekBar in Android UI controls

SeekBar is an Android UI Control which is an extension of ProgressBar Class with an addition of drag-able thumb, the user can touch the thumb and drag left or right to set the current Progress level.

seekbar

.xml file:

<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:background=”#ff009924″
tools:context=”com.CoreProgrammers.android.seekbar.MainActivity” >

<SeekBar android:id=”@+id/seekBar1″
android:layout_width=”400dp”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_alignParentTop=”true”
android:layout_marginTop=”26dp”
android:background=”#ffff2244″
android:thumb=”@drawable/ic_launcher”
android:scrollbarStyle=”outsideInset”
android:max=”100″/>

<TextView android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:layout_below=”@+id/seekBar1″
android:layout_marginLeft=”29dp”
android:layout_marginTop=”14dp” />

</RelativeLayout>

Java file:

 

package com.CoreProgrammers.android.seekbar;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity{

private SeekBar seekBar;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState)
{

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeVariables();

textView.setText(“Covered: ” + seekBar.getProgress() + “/” + seekBar.getMax());

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
int progress = 0;

@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser)
{
progress = progresValue;
textView.setText(“Covered: ” + progress + “/” + seekBar.getMax());
}

@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
Toast.makeText(getApplicationContext(), “Started tracking seekbar”, Toast.LENGTH_SHORT).show();
}

@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
Toast.makeText(getApplicationContext(), “Stopped tracking seekbar”, Toast.LENGTH_SHORT).show();
}
});
}

private void initializeVariables()
{
seekBar = (SeekBar) findViewById(R.id.seekBar1);
textView = (TextView) findViewById(R.id.textView1);
}
}

RatingBar in Android UI Controls

ratingbarAndroid RatingBar is used to Accept and display the user rating. This Control shows the number of stars in which the user can touch/drag to set the value in Android, We can create the rating bar(rating stars) using the tag in xml UI Layout file.

eg:

<android:layout_width="wrap_content"
android:layout_height="30dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="28dp" />
RatingBar

followings are the Properties of Android RatingBar control : a) android:isIndicator : this Attribute takes a boolean value either true or false, if this Property is set to true than the RatingBar will be non-changeable by the user, in other words the RatingBar will be Act like Indicator. b) android:numStars : this takes the integer value which indicates the number of stars to be displayed in the RatingBar control. c) android:raing : this takes a float value input which will be the default Rating, which is going to be the displayed in the rating bar control, when the RatingBar is loaded for first time. d) android:stepSize: this Attribute take a float value which is the step size of the rate(rating) increased or decried. for eg. if we set the step size to 1.0 than the rating value will be increased or decried by 1, and if have given step size of 0.5 than the rating size will be increased or decried by 0.5 .

xml file:-

<xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

android:numStars="7"
android:stepSize="0.25"
android:layout_width="wrap_content"
android:layout_height="30dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginTop="28dp" />

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/ratingBar1"
android:layout_below="@+id/ratingBar1" />


Java file:-

package com.coreprogrammers.ratingbardemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity
{

        /**
        * Rating bar instance
        */
        RatingBar ratingBar;
        /**
        * Customized Rating text
        */
        TextView ratingText;
        
        /**
        * @see android.app.Activity#onCreate(android.os.Bundle)
        */
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            ratingText = (TextView) findViewById(R.id.rating);
            
            ratingBar = (RatingBar) findViewById(R.id.ratingBar1);
        
            ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
            {
                    @Override
                    public void onRatingChanged(RatingBar ratingBar,floatrating, boolean fromUser)
                    {
                        final int numStars = ratingBar.getNumStars();
                        ratingText.setText(rating + "/" + numStars);
                    }
            });
        
        }

}
 

Java Code


        

DatePicker in Android UI controls

DatePicker is an Android UI Control which allows the user to select the date consisting of day, month and year in any custom user interface, to achieve this functionality Android Provides DatePicker dialog components/class.

Important Methods of the DatePicker control:

1) getDayOfMonth() :- This method of DatePicker control returns the selected day of month.

2) getMonth() :- This method of DatePicker control returns the selected month.

3) getYear() :- This method of DatePicker control returns the selected year.

4) setMaxDate(long maxDate) :- This method of DatePicker control, sets the maximum date supported by the DatePicker control in milliseconds started from January 1, 1997 00:00:00 .

5) setMinDate(long minDate) :- This method of DatePicker control, sets the minimum date supported by the DatePicker control in milliseconds started from january 1 , 1997 00:00:00 .

6) setSpinnerShown(boolean shown) :- This method of DatePicker control, sets the spinner of the DatePicker controlto true or false.

7) updateDate(int year, int month, int dayOfMonth) :- This method of DatePicker class is a very Important method which sets the date in the DatePicker control provided by the user or the developer.

DatePicker

.xml file:


java file:

package com.example.androiddatepicker;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;

public class MainActivity extends Activity
{
private ImageButton imageButton;
private Calendar cal;
private int day;
private int month;
private int year;
private EditText editText;

private DatePickerDialog.OnDateSetListener datePickerListener;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

imageButton = (ImageButton) findViewById(R.id.imageButton);

cal = Calendar.getInstance();
day = cal.get(Calendar.DAY_OF_MONTH);
month = cal.get(Calendar.MONTH);
year = cal.get(Calendar.YEAR);

editText = (EditText) findViewById(R.id.editText);

imageButton.setOnClickListener(new OnClickListener()
{
@SuppressWarnings(“deprecation”)
@Override

public void onClick(View v)
{
showDialog(0);
}
});

datePickerListener = new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay)
{
editText.setText(selectedDay + “-” + (selectedMonth + 1) + “-” + selectedYear);
}
};

}

@Override
@Deprecated
protected Dialog onCreateDialog(int i)
{
DatePickerDialog _objDatePickerDialog;

_objDatePickerDialog=new DatePickerDialog(MainActivity.this, datePickerListener, year, month, day);

return _objDatePickerDialog;
}

}

TimePicker Control in Android UI Controls

Android Time Picker is a control which allows the user to select the time or the day in either 24 h format or in AM/PM format. Time is consist of hour, minute, and clock format. We can create a time picker using the TimePicker Class.

How to define a TimePicker in an Android Project:

for using this control in our Android Application,first of all we have to define the Picker in our UI xml file in the following way:-

and in our Java file following is the syntax:-

private TimePicker timePicker;
timePicker = (TimePicker) findViewById(R.id.timePicker);

to get the current hour and the current minute, we will use the following syntax:-

int hour= timepicker.getCurrentHour();
int min= timepicker.getCurrentMinute();

Important Methods of the TimePicker controls:

a) is24HourView() :- this method is used to check that if the TimePicker Control is set to 24 h format or not.
if it is set to 24 h format than this method will return true otherwise false.

b) isEnabled() :- this returns the enable status for TimePicker Control.

c) setCurrentHour(Integer CurrentHour) :- this method sets the current hour of the TimePicker provided by the user/developer.

d) setCurrentminute(Integer CurrentMinute) :- this method sets the current minute of the TimePicker provided by the user/developer.

e) setEnabled(boolean enabled) :- this sets the enabled state of the TimePicker control.

f) setis24HourView(boolean is24hView) :- this sets weather the TimePicker works in 24 h format or in AM/PM format.

g) setOnTimeChangeListener(TimePicker.onTimeChangedListener onTimeChangedListener) :- this method is the call back listener event which is called at the time, when the time is changed or Adjust by the user.

.xml file:-

String file:

TimePicker_Demo
Hello world!
Settings
Time Picker Example
Pick the time and press save button
Save

The Time is:

.java file:

package coreprogrammers.example.timepicker_demo;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity extends Activity
{

private TimePicker timePicker1;
private TextView time;
private Calendar calendar;
private String format = “”;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
timePicker1 = (TimePicker) findViewById(R.id.timePicker1);
time = (TextView) findViewById(R.id.textView1);
calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int min = calendar.get(Calendar.MINUTE);
showTime(hour, min);
}

public void setTime(View view)
{
int hour = timePicker1.getCurrentHour();
int min = timePicker1.getCurrentMinute();
showTime(hour, min);
}

public void showTime(int hour, int min)
{
if (hour == 0)
{
hour += 12;
format = “AM”;
}
else if (hour == 12)
{
format = “PM”;
}
else if (hour > 12)
{
hour -= 12;
format = “PM”;
}
else
{
format = “AM”;
}

time.setText(new StringBuilder().append(hour).append(” : “).append(min)
.append(” “).append(format));

}

}

Spinner in Android UI Control

Spinner Provide a quick way to select a one value from a set.

In a default state a spinner shows its currently selected value when the user touches the spinner, a drop-down menu get displayed in a list form, from which the user can select a new option from the set.

device-2015-01-06-214252

.xml file:

<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/spinner1″
android:layout_width=”200dip”
android:layout_height=”wrap_content”
android:prompt=”@string/spinner_prompt” />

<Button android:id=”@+id/btnSubmit”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Click here”
android:paddingTop=”20px” />

</LinearLayout>

 

.java file:

package com.coreprogrammers.androidspinnerdemo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity
{

private Spinner spinner1;
private Button btnSubmit;

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

spinner1 = (Spinner) findViewById(R.id.spinner1);

List<String> list = new ArrayList<String>();

list.add(“Android”);
list.add(“Java”);
list.add(“MatLab”);
list.add(“C Language”);
list.add(“PHP”);

ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,list);

spinner1.setAdapter(dataAdapter);

// Button click Listener
addListenerOnButton();

}

public void addListenerOnButton()
{

btnSubmit = (Button) findViewById(R.id.btnSubmit);

btnSubmit.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{

Toast.makeText(MainActivity.this, “On Button Click : ” + “\n” + String.valueOf(spinner1.getSelectedItem()) , Toast.LENGTH_LONG).show();
}

});

}

}

Progress Bar In Android UI Control

Progress  bar is used to show progress of a task.

for example when we are uploading or downloading something from internet, it is better to show the progress of download/upload to the. In Android there is a class call progress dialog that allows you to create a progress bar in order to do this we have to instantiate an object of this class.

device-2015-01-05-215451

 

 

 

 

Syntax is: progressdialog progress= new progressdialog(activity.this);

 

.xml file:

<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"
tools:context=".MainActivity" >

<ProgressBar android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />

<TextView android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar1"
android:layout_below="@+id/progressBar1"/>

</RelativeLayout>

java file:

package com.coreprogrammers.androidprogressbardemo;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends Activity 
{
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;
private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

progressBar = (ProgressBar) findViewById(R.id.progressBar1);

textView = (TextView) findViewById(R.id.textView1);

// Start long running operation in a background thread
new Thread(new Runnable() 
{
public void run() 
{
while (progressStatus < 100) 
{

progressStatus += 1;
//progressStatus=progressStatus+1;
// Update the progress bar and display the 



try 
{
// code runs in a thread
runOnUiThread(new Runnable() 
{
@Override
public void run() 
{
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
}
catch (final Exception ex)
{
Log.i("---","Exception in thread");
}


try 
{
//Sleep for 200 milliseconds. 
//Just to display the progress slowly
Thread.sleep(200);
} 
catch (InterruptedException e) 
{
e.printStackTrace();
}

}
}


}).start();

}



}

 

Auto-complete Text View

Auto-complete text view is an edit text that shows a list of suggestions automatically when the user is typing the list of suggestions is displayed in a drop-down menu, the user can choose an item from the drop-down list to replace the content of auto-complete text view.

followings are the attributes of Auto-complete text view:-

  1. android:completionHint :- this defines the hint which is to be displayed in the drop-down menu.
  2. android:completionHintView:– this defines the hint view displays in the drop-down menu.
  3. android:completionThreshhold:- this defines the number of characters that the user must type before completion suggestions are displayed in the drop-down menu.
  4. android:dropDownAnchor:- this is the view to anchor the auto-complete drop-down tool.
  5. android:dropDownHeight:- this specifies basic height of drop-down menu.
  6. android:dropDownHorizontaloffset:- this specifies the amount of pixels by which the drop-down should be off set horizontally.
  7. android:dropDownselector:- this specifies a selector in a drop down list.
  8. android:dropDownVerticaloffset:- this specifies the amount of pixels by off set vertically.
  9. android:dropDownWIdth:- this specifies the basic width of the drop down.
  10. android:popupBackground:- this sets the background of the pop-up.

example of auto-complete text view:-

  .xml file :- 

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"
tools:context="${relativePackage}.${activityClass}" >

<TextView android:id="@+id/textView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_alignParentTop="true" 
android:layout_marginTop="15dp" 
android:layout_marginLeft="36dp" 
android:text="what is your favourite programming language" /> 

<AutoCompleteTextView android:id="@+id/autoCompleteTextView1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_below="@+id/textView1" 
android:layout_marginLeft="36dp" 
android:layout_marginTop="17dp" 
android:ems="10" 
android:text=""> 

<requestFocus /> 
</AutoCompleteTextView>

</RelativeLayout>

   .java file:- 

package com.coreprogrammers.autocompletetextviewdemo;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;


public class MainActivity extends Activity 
{

String[] language ={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP","Matlab","R Programming","oracle","My Sql"}; 
@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 

//Creating the instance of ArrayAdapter containing list of language names 
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.select_dialog_item,language); 


//Getting the instance of AutoCompleteTextView 
AutoCompleteTextView autoCompleteTextView1= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); 

autoCompleteTextView1.setThreshold(2);//will start working from first character 
autoCompleteTextView1.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView 

autoCompleteTextView1.setTextColor(Color.RED); 
}
}

 

 

 

print of the calendar for a given year Using C Language

The following program prints the calendar for a given year like Unix’s cal utility.
However, it won’t work exactly like “cal” for year-wise output. For that you need to store the
output in an array as a grid.

#include <stdio.h>
#include <stdlib.h>
int Days_Tbl[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
char *Month_Tbl[12] = {
"January", "February", "March", "April", "May",
"June", "July", "August", "September",
"October", "November", "December"
};
int FirstDayOfMonth( int m, int y );
void PrintCalendar( int m, int y );
int FirstDayOfMonth( int m, int y )
{
int i, leap;
long d;
if ( y>1752 ) /* for Gregorian Calendar */
{
leap = ( y%4==0&&y%100!=0 || y%400==0 );

d = 365L*1752 + 1752/4;
d += 365L*(y-1752-1) + (y-1752-1)/4 - (y-1752-1)/100
+ (y-1752-1)/400 + 6;
}
else
/* for Julian Calendar */
{
leap = ( y%4==0 );
d = 365L*(y-1) + (y-1)/4 + 6;
}
for( i=1; i<m; ++i )
d += Days_Tbl[leap][i-1];
if ( y>1752 || (y==1752 && m>9) )
d -= 11;
return( d % 7 );
} /*--FirstDayOfMonth( )--------*/
void PrintCalendar( int m, int y )
{
int i, leap, firstdayofmonth;
firstdayofmonth = FirstDayOfMonth( m, y );
leap = ( y>1752 ) ? ( y%4==0&&y%100!=0 || y%400==0 ) : ( y%4==0 );
printf( "%13s - %d\n", Month_Tbl[m-1], y );
printf( "Sun Mon Tue Wed Thu Fri Sat\n" );
for ( i=0; i<firstdayofmonth ; ++i )
printf( "
" );
for ( i=1 ; i<=Days_Tbl[leap][m-1] ; ++i )
{
printf( "%3d ", i );
if ( (firstdayofmonth + i)%7 == 0 )
printf("\n");
if (y==1752 && m==9 && i==2)
{
i += 11;
firstdayofmonth += 3;
}
}
printf( "\n" );
} /*--PrintCalendar( )-----*/
int main( int argc, char *argv[ ] )

{
int m, y;
switch( argc )
{
case 1:

printf( "Syntax: cal [month] year \n" );
break;
case 2:
y = atoi( argv[1] );
for ( m=1 ; m<=12 ; ++m )
{
PrintCalendar( m, y );
printf( "Press <ENTER>....\n" );
getchar( );
}
break;
case 3:
m = atoi( argv[1] );
y = atoi( argv[2] );
PrintCalendar( m, y );
}
return(0);
} /*--main( )----*/

 

Set Latest Java as default JVM on Mac OSX Mavrix and Above

I recently had an issue where an application I wanted to run on Mountain Lion needed Java 7 as the default JVM on the machine. The install for the app in question worked without errors, but the issue was highlighted when trying to run the app.

Here’s how I fixed the problem.

Firstly, open Terminal and find out the current default Java version on your machine:

java -version

Download the Java 7 JDK from the Java SE site (http://www.oracle.com/technetwork/java/javase/downloads/index.html)

Run the installer. Now, for me this still didnt ensure that the updated Java version was the current one used by the system.

In Terminal, navigate to the following location:

cd /System/Library/Frameworks/JavaVM.framework/Versions/

The CurrentJDK symlink in this directory was still pointing to an older Java version. To resolve this, remove the symlink and create a new one pointing to the new Java 7 JDK (you may need to use sudo to run these commands):

rm CurrentJDK
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/ CurrentJDK

This fixed it for me. To confirm, check the Java version once again in Terminal:

java -version

You should now see java version

Skip to toolbar