Tampilkan postingan dengan label manifest. Tampilkan semua postingan
Tampilkan postingan dengan label manifest. Tampilkan semua postingan

How to align your TabHost at the bottom of the screen

Posted by Unknown Kamis, 14 November 2013 0 komentar
There is a simplest way to align Tabbar at the bottom of the page.
The code is given below copy and download the code and try it...

In the previous example we learned a simple example to add Tabs to our application.Only a small change can give you tabs at the bottom of the page.

In the previous example the xml was like this...
 

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

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

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

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

</LinearLayout>

Instead of using Linear Layout use Relative Layout like below and use "android:layout_alignParentBottom="true"" for Tab Widget.
 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<RelativeLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">


<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

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

</TabHost>

Baca Selengkapnya ....

Change Tabbar Text (title) dynamically in Android - a simple example

Posted by Unknown Senin, 11 November 2013 0 komentar
Changing title of tabbar is bit easier in android
Copy and download the code below and try it....

Basic tabbar tutorials see here...
 
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;
import android.widget.TextView;
import android.app.TabActivity;
import android.content.Intent;


public class MainActivity extends TabActivity {

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

/** TabHost will have Tabs */
tabHost = (TabHost)findViewById(android.R.id.tabhost);

TabSpec firstTabSpec = tabHost.newTabSpec("tab_id1");
TabSpec secondTabSpec = tabHost.newTabSpec("tab_id2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tab_id3");

firstTabSpec.setIndicator("First").setContent(new Intent(this,Tab1.class));
secondTabSpec.setIndicator("Second ").setContent(new Intent(this,Tab2.class));
thirdTabSpec.setIndicator("Third").setContent(new Intent(this,Tab3.class));


tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);

tw = getTabWidget();
View tab1View = tw.getChildAt(0);
tab1View.setId(1);

View tab2View = tw.getChildAt(1);
tab2View.setId(2);

View tab3View = tw.getChildAt(2);
tab3View.setId(3);

tab1View.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
((TextView)tabHost.getTabWidget().getChildAt(v.getId()-1).findViewById(android.R.id.title)).setText("my Tab " + v.getId());
}
});

tab2View.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
((TextView)tabHost.getTabWidget().getChildAt(v.getId()-1).findViewById(android.R.id.title)).setText("my Tab " + v.getId());
}
});

tab3View.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
((TextView)tabHost.getTabWidget().getChildAt(v.getId()-1).findViewById(android.R.id.title)).setText("my Tab " + v.getId());
}
});

} }



Baca Selengkapnya ....

Using TabHost to create a simple Tabbar application - An Android Example

Posted by Unknown Minggu, 10 November 2013 0 komentar
For creating a tabbar application first create a tabhost object to create tabs
In activity_main.xml we create TabHost and specify a layout where we are going to insert the tabs.
Copy and download the code and try it yourself....

Now we are going to create three tabs.
Lets us now first make the xml for it

activity_main.xml :
TabHost provided flexibility of managing data in different views by providing tabbed interface(compared to TabLayout). TabHost basically a container, where you need to put tab widget, which will host tabbed interface and FrameLayout, within which the different views are presented.
  • TabHost ( main container of tab view )
  • TabWidget ( used to navigate between tabs )
  • FrameLayout ( for tab content )
 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

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

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

</LinearLayout>

tab1.xml :
 
<?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:text="TAB1 DATA"
android:padding="15dip"
android:textSize="18dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
tab2.xml :
 
<?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:text="TAB2 DATA"
android:padding="15dip"
android:textSize="18dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
tab3.xml :
 
<?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:text="TAB3 DATA"
android:padding="15dip"
android:textSize="18dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
Now create three java class for each of the tabs..

Tab1.java :
 
import android.app.Activity;
import android.os.Bundle;

public class Tab1 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
}
}
Tab2.java :
 
import android.app.Activity;
import android.os.Bundle;

public class Tab2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
}

}
Tab3.java :
 
import android.app.Activity;
import android.os.Bundle;

public class Tab3 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tab3);
}

}
Donot forget to introduce the newly created java class to the android manifest file...

AndroidManifest.xml
 



Mainactivity.java
  • TabSpec used to create a new tab.
  • By using TabSpec only we can able to setContent to the tab.
  • By using TabSpec setIndicator() we can set name to tab.
 
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.app.TabActivity;
import android.content.Intent;


public class MainActivity extends TabActivity {

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

/** TabHost will have Tabs */
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

TabSpec firstTabSpec = tabHost.newTabSpec("tab_id1");
TabSpec secondTabSpec = tabHost.newTabSpec("tab_id2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tab_id3");

firstTabSpec.setIndicator("First").setContent(new Intent(this,Tab1.class));
secondTabSpec.setIndicator("Second ").setContent(new Intent(this,Tab2.class));
thirdTabSpec.setIndicator("Third").setContent(new Intent(this,Tab3.class));

tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);

} }


Baca Selengkapnya ....

Android Application Fundamentals or Components

Posted by Unknown Senin, 06 Mei 2013 0 komentar

See more basics on Android along with interview questions

Android is written in java programming language.Android application are composed of some of the main components such as:
  • Activities
  • Services
  • Content providers
  • Broadcast receivers
Intents, Resources(such as strings and graphics), Notification signalings(light,sound,dialog), are also part of the components.

All these components play different role in the overall application and each one can be activated individually.

Activities :
          An activity represents a single screen with a user interface.Suppose if there is a listview and if clicking on each row it traverse to another page ,then the screen showing listview is an activity and the next page is another activity,where each one is independent of the others.
An activity is implemented as a subclass of Activity ,that why we use

see activity life cycle here :

public class MainActivity extends Activity {
}
Services :
          A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.For example : Running an alarm in background
A service is implemented as a subclass of Service.

Content providers :
          They manages a shared set of application data.Data can be stored in SQLite Database,File systems,web or any other medium where application can access.
Content Providers allows to modify and use these stored data.For example : storing users contacts details,where proper permission one can get the contacts.
A content provider is implemented as a subclass of ContentProvider.

Broadcast receivers :
          They responds to systems  broadcast announcements.Some of the native Broadcast are volume control, light, switch on and off, screen on and off,bluetooth etc.A broadcast receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.
A broadcast receiver is implemented as a subclass of BroadcastReceiver.

Who Activates A component ?
         The above components are activated by a message called Intents.
Intents bind individual components to each other at runtime, whether the component belongs to your application or another.
An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.

What is a Content Resolver ?
         The Content Provider, is not activated by intents. It is activated when there is request from ContentResolver. These Resolvers handles direct transaction with the providers so they donot need further any method calls. This leaves a layer of abstraction between the content provider and the component requesting information (for security).

What is an AndroidManifest file ?
          This is a root directory of Android application where all the components are declared.Other than this they also have
  • user permissions the application requires, such as read and write external storage
  • Declare the minimum API level
  • Declare hardware and software features such as bluetooth or a printer
  • API libraries etc...
 




Baca Selengkapnya ....

Broadcast Receiver Introduction in Android

Posted by Unknown Rabu, 03 April 2013 0 komentar
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 automaticaly called
}
}
Register through manifest
Register broadcast receiver Via the AndroidManifest.xml file.
 





When android.intent.action.PHONE_STATE Event will fire ( call recieved/pick/end ), then onReceive method in PhoneCall.java file will automaticaly call.
Now Create PhoneCall.java file
 
// 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 automaticaly called
}}

Baca Selengkapnya ....

TextView with link in ANDROID…….

Posted by Unknown Senin, 04 Maret 2013 0 komentar
in java class:
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;

public class TextViewLinkDemo extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText( Html.fromHtml("This is a textView with a link " +"
AngelMark Blog "
+ "created in the Java source code using HTML."));
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
}
main.xml:

<?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/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>
In Manifest file give internet permission

Baca Selengkapnya ....
Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of android populer.