Skip to main content

Posts

Showing posts from April, 2013

Customized Spinners in Android

See more basics on Android along with interview questions The Android Spinner Control is definitely the equivalent of the drop-down selector . By making use of spinner control you basically obtain the capability to choose from a list without taking up all of the display screen space of a ListView. Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. You can add a spinner to your layout with the Spinner object. You should usually do so in your xml layout with a  <spinner>   element. For example: <Spinner     android:id="@+id/myspinner"     android:layout_width="fill_parent"     android:layout_height="wrap_content" /> Also See....Simple Spinners In Android Here we are going to deal with Customized Spinners.Her...

BroadcastReceiver for Screen On/Off in ANDROID

If wanted to call a broadcast for screen on/off you can get the code sniffet from here. Here I have used dynamic calling of Broadcast and the java source code is given below. get more details about broadcast from :    Broadcast Receiver Introduction in Android    BroadcastReceiver to get Battery Level in java file: public class MainActivity extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.i("[BroadcastReceiver]", "MyReceiver"); if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){ Log.i("[BroadcastReceiver]", "Screen ON"); } else if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){ Log.i("[BroadcastReceiver]", "Screen ...

Google CEO Confirms that Glass Runs on Android

It's official: Google Glass is based on Android. We kinda saw this one coming: Google Glass is based on Android. Company CEO Larry Page made the revelation during Google's 1Q13 earnings call on Thursday. Towards the end of the call (1:08), Page responded to a question about the amount of "incremental engagement" Google will see over the next several years regarding the company's products and new form factors like Glass. The questioner also asked how transportable Android will be across these new form factors. read more: http://www.tomshardware.com/news/Google-Glass-Ice-Cream-Sandwich-Larry-Page-Incrimental-Engagement-Earnings-Call,22133.html

Template proposals Not Working in Eclipse "No Default Proposals"

while we are using Eclipse we may see that the default proposal are not appearing when we press ctrl+space.This is due to some settings changes in the Windows/preference/java/Editor/Content Assist/Advanced If default proposal is not appearing go to Windows/preference/java/Editor/Content Assist/Advanced Then you will see a window like this.. Here you can check the apprpreate check boxes (java proposals) Then coming back you can get the default proposals pressing ctrl+space

Use Your Own SQLite in ANDROID Application or Using 'SQLite Asset Helper' to read your own databases stored in Asset folder

See more basics on Android along with interview questions See SQLite tutorial here If you want to read your own databases in ANDROID APPLICATION, this post may help you. You may be familiar by creating SQLite in Android use  SQLiteOpenHelper . Here we are going to deal with using our own databases.  I have a database named 'mydatabase.sqlite', which consist of a set of name and age of 5 students. Suppose I want to view the database, I can use SQLite database browser which you can download from here.                                                     download browser..... Through this browser we can view the databases, can even modify delete or create a new one. 'mydatabase.sqlite' with name and age of five students is browsed and viewed as shown below Now  make a zip format of database and copy this database to asse...

Falling Animation in ANDROID using Animation of Translate

Falling animation is used to bring transition to a view between two X points or two Y points. In Android, you can apply this scaling effect to almost anything, from simple text, to images, buttons, etc… in res/anim/falling.xml suppose if transition to be done between two different X indexes use.. <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="2000"/> </set> suppose if transition to be done between two different Y indexes use.. <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <translate android:fr...

Scaling Animation In ANDROID

Scaling animation is used to scale a view. In Android, you can apply this scaling effect to almost anything, from simple text, to images, buttons, etc…  Here simply I will explain a scaling textview which you can apply to other views also... In res/anim/scale.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator"> <scale android:fromXScale="0.0" android:toXScale="1.0" android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%" android:pivotY="50%" android:duration="2000" /> </set> Java source code is given below public class Textviewanimation extends Activity { Animation fadeIn,fadeOut; TextView tv; Button startanimation; @Override public void onCreate(Bundle savedInstanceState) ...

TextView Animation or Alpha animation (FadeIn , FadeOut) in ANDROID

An Alpha Animation is animation that controls the alpha level of an object, i.e. fading it in and out. In Android, you can apply that fading effect to almost anything, from simple text, to images, buttons, check boxes, etc…   This can be done both from xml and from java class. Here I will explain a simple way to give a FadeIn and FadeOut for a textview on button click.. public class Textviewanimation extends Activity { Animation fadeIn,fadeOut; TextView tv; Button startanimation; Boolean fadeflag=true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_textviewanimation); tv=(TextView) findViewById(R.id.textview); startanimation=(Button) findViewById(R.id.button1); fadeIn = new AlphaAnimation(0.0f , 1.0f ) ; fadeIn.setDuration(1200); fadeIn.setFillAfter(true); fadeOut = new AlphaAnimation(1.0f , 0.0f); fadeO...

What is a TEXTWATCHER in ANDROID ?

TextWatcher is used to keep watch on EditText while entering data into it. We can perform operation and keep watch on which characters are being entered or how many characters are being entered in the EditText.   Text Watcher has three events.  1. beforeTextChanged : This means that the characters are about to be replaced with some  new text. The text is uneditable. This event is used when you need to take a look at the old  text which is about to change.  2. onTextChanged: Changes have been made, some characters have just been replaced. The text is uneditable. This event is used when you need to see which characters in the text are new.  3. afterTextChanged : The same as above, except now the text is editable. This event is used when you need to see and possibly edit new text.   Java source code is given below EditText myedittext; myedittext = (EditText)findViewById(R.id.edittext); myedittext.addTextChangedListener(new TextWa...

WhatsApp CEO: We Have Bigger User Base Than Twitter

WhatsApp was initially released as a free app, but now is gradually phasing into a subscription app, charging 99 cents per year. The app has stayed clear of advertisements. "We do have a manifesto opposing advertising," Koum said in an interview with allthingsd...  see more: http://www.gizbot.com/apps-software/whatsapp-ceo-we-have-bigger-user-base-than-twitter-011730.html

Swipe To Change Page in ANDROID or Page Swiping Using ViewPager FragmentActivity in ANDROID

See more basics on Android along with interview questions Here we are going to deal with horizontal view swiping with ViewPager.The ViewPager control (android.support.v4.view.ViewPager) provides the horizontal swiping behavior. It can be used within your layouts much like a Gallery or other adapter-populated user interface control would be. The PagerAdapter (android.support.v4.view.PagerAdapter) class is used to define the data displayed by the ViewPager control. Here we are going to load a string from json(kept in text file in asset folder) in the swiping view. Here we go with java source code public class Viewpagers extends FragmentActivity { // android.support.v4.app.FragmentStatePagerAdapter. SectionsPagerAdapter mSectionsPagerAdapter; // The ViewPager that will host the section contents. ViewPager mViewPager; String text; JSONArray jArray; ArrayList<String> Questionarray = new ArrayList<String>(); ArrayList<String> Answerarray = new Array...

BroadcastReceiver to get Battery Level - simple Example using dynamic calling of BroadCast in ANDROID

See Introduction for Broadcast Receiver here:  When you need to call a broadcast (suppose here battery value) you need to register the broadcast and when the event is published it will call onReceive method which have context and particular intent as parameter. public class Broadcast extends Activity { //Create broadcast object BroadcastReceiver mybroadcast = new BroadcastReceiver() { //When Event is published, onReceive method is called @Override public void onReceive(Context context, Intent intent) { //Get battery percentage int batterylevel = intent.getIntExtra("level", 0); //get progressbar ProgressBar myprogressbar = (ProgressBar) findViewById(R.id.progressbar); myprogressbar.setProgress(batterylevel); TextView tv = (TextView) findViewById(R.id.textfield); //Set TextView with text tv.setText("Battery Level: " + Integer.toString(batterylevel) + "%"); } }; @Override p...

Broadcast Receiver Introduction in Android

A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. There are two ways to use broad cast receiver in android -- One is using dynamically in activity Second to register through manifest Using dynamically in activity Register broadcast receiver Via dynamically ( Run time ) // Create reciever object private BroadcastReceiver the_receiver = new PhoneCall(); // Set When broadcast event will fire. private IntentFilter filter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED); // Register new broadcast receiver this.registerReceiver(the_receiver, filter); // Reciever class which extends BroadcastReceiver public class PhoneCall extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { // Phone call state change then this method will au...

How to Open Calculator In ANDROID

If we want to open the inbuilt calculator of ANDROID ,here is the sniffet... public class CalculatorActivity extends Activity { public static final String CALCULATOR_PACKAGE ="com.android.calculator2"; public static final String CALCULATOR_CLASS ="com.android.calculator2.Calculator"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent calculatorintent = new Intent(); calculatorintent.setAction(Intent.ACTION_MAIN); calculatorintent.addCategory(Intent.CATEGORY_LAUNCHER); calculatorintent.setComponent(new ComponentName(CALCULATOR_PACKAGE,CALCULATOR_CLASS)); CalculatorActivity.this.startActivity(calculatorintent); } } The above may not work with every devices, so you may need this one.. ArrayList<HashMap<String,Object>> items =new ArrayList<HashMap<String...

How To Finish All Previous Activities in ANDROID ?

Some times we may need to close previous all activities before calling an intent, so that the previous activity do not loads on clicking the Android back button.Here is a simple sniffet for it.. Intent intent = new Intent(getApplicationContext(), MainClass.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);

EditText With Long Default Text On A single Line in ANDROID

Sometimes we may need to include a long default text on a single line in EditText, for that we can set the EditText to single line and provide a horizontal scroll. <EditText android:id="@+id/EditTextValue" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:singleLine="true" android:scrollHorizontally="true" android:text="This is a big text to be included in the edittext so added a horizontal scroll..."/ >