Advertisements

Aatul Palandurkar

Archive for July 2013

Objectives :

  • How to set TextView in Android?
  • How to add TextView in Android?
  • How to add TextView in Android via Java program?
  • How to set Layout parameters from Java code in Android?

TextView is a one of the Views available in Android. There are two (2) ways to add TextView in your Android application as follows :

  1. Using XML code
  2. Using Java code

XML Code example – Adding to a TextView in a layout xml file

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:orientation="vertical" >

 <TextView
  android:id="@+id/textView"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Hello World" />

</LinearLayout>

 

Java Code example – Creating and adding a new TextView to a Layout

// Creates object of TextView
TextView textView = new TextView(this);
// Set text to display in TextView on Screen
textView.setText(“Hello World”);
// Add TextView to Linear Layout with layout parameters
((LinearLayout)findViewById(R.id.mainLayout))
 .addView(textView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

Above Java code can be written in onCreate() of your Activity.

Here LayoutParams.FILL_PARENT will set layout height to FILL_PARENT, LayoutParams.WRAP_CONTENT will set layout width to WRAP_CONTENT.

Posted from WordPress for Android

Advertisements

Objective :

  • How to write HelloWorld Application in Android?
  • How to write HelloWorld App in Android?
  • How to write HelloWorld in Android?

To create HelloWorldApp follow the steps below :

  • Go to File Menu > Go to New > Click on Android Application Project.

  • In New Android Application Window, enter Application Name as “HelloWorldApp”. Do not change anything else and click Next.

  • While you are in Configure Project Window, uncheck the Create custom launcher icon. Do not change anything else. Click Next.

  • In Create Activity window, click Next.

  • In Blank Activity Window, change the Activity Name to “HelloWorldApp”. Do not change anything else. Click Finish. And your HelloWorldApp Android application will be created.

Here is snapshot of HelloWorldApp project structure :

HelloWorldApp Project Structure in Android

XML Code for UI

File : activity_hello_world_app.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 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:text="@string/hello_world" />

</RelativeLayout>

XML code which manages all the string items or labels.

File : strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorldApp</string>
 <string name="action_settings">Settings</string>
 <string name="hello_world">Hello world!</string>
</resources>

Java Code

File : HelloWorldApp.java

package com.example.helloworldapp;

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

public class HelloWorldApp extends Activity {

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

}

After writing your code, to run this snippet you need an AVD (Android Virtual Device) or Emulator. Here is tutorial link which will help you to create AVD so as to run your Android application.

Objectives :

  • How to create AVD?
  • How to create Android Virtual Device?
  • How to create Emulator for Android?
  • What is AVD (Android Virtual Device)?

AVD (Android Virtual Device) / Emulator

AVD (Android Virtual Device) is an Emulator which helps in running Android applications onto your computer/laptop and you don’t need physical device every time you write/change code. Using an AVD you can run and test nearly every feature of your application right from simple text, GPS, Camera, Database, etc.

Creating AVD :

  • To create go to Window menu > Click on “Android Virtual Device Manager” or “AVD Manager” option.

  • In Android Virtual Device Manager or AVD Manager window, click New button.

  • In Create new Android Virtual Device (AVD) window, set credentials for new AVD you wish to create, press OK.

  • Select AVD you have created from the list and click Start > click Launch.

  • Here is an AVD you have created, now you are ready to run your Android application.

You can have a look at this tutorial so that you can Quickstart Android Application Development. So start writing your Android applications now.

Objectives :

  • What is APN Setting for Airtel USB Modem?
  • What is APN Setting for Idea USB Modem?
  • What is APN Setting for BSNL USB Modem?
  • What is APN Setting for Vodafone USB Modem?
  • What is APN Setting for Aircel USB Modem?
  • What is APN Setting for Tata Docomo USB Modem?
  • What is APN Setting for Reliance USB Modem?
  • What is APN Setting for Uninor USB Modem?

 

Airtel APN Setting :

Profile Name: Airtel
APN : airtelgprs.com
Access Number: *99#

Idea APN Setting :

Profile Name: Idea
APN : Internet
Access Number: *99#

BSNL APN Setting :

Profile Name: BSNL
APN : bsnlnet
Access Number: *99#

Vodafone APN Setting :

Profile Name: Vodafone
APN : www
Access Number: *99#

AirCel APN Setting :

Profile Name: Aircel
APN : aircelgprs
Access Number: *99***1#

Tata Docomo APN Setting :

Profile Name: Docomo
APN : tata.docomo.internet
Access Number: *99#

Reliance APN Setting :

Profile Name: Reliance
APN : rcomwap
Access Number: *99#

Uninor APN Setting :

Profile Name: Uninor
APN : Uninor
Access Number: *99#

Enjoy internet surfing now.


Advertisements

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 8,907 other followers

Tweets

YouTube

%d bloggers like this: