How to set the text inside my tab widget - android

I want to change text in my tab Bar to get text in singleLine and remove the bold style but how to do it ? Please show me the good way
My below code don't change anything...
Here my XMl code:
<?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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_gravity="right">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text1"
android:text="#string/text_v1"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text2"
android:text="#string/text_v2"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text3"
android:text="#string/text_v3"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text4"
android:text="#string/text_v4"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="#+id/text5"
android:text="#string/text_v5"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Here the java code:
package com.atonfoaziz.tabs5;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
TabHost.TabSpec spec;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tabHost = (TabHost)findViewById(R.id.tabHost);
if (tabHost != null){
tabHost.setup();
spec = tabHost.newTabSpec("Tab I").setContent(R.id.linearLayout1).setIndicator("Contacts");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab II").setContent(R.id.linearLayout2).setIndicator("Calls");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab III").setContent(R.id.linearLayout3).setIndicator("Discussions");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab IV").setContent(R.id.linearLayout4).setIndicator("Research");
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tab V").setContent(R.id.linearLayout5).setIndicator("Settings");
tabHost.addTab(spec);
TabWidget widget = tabHost.getTabWidget();
int tabCount = widget.getTabCount();
for (int i = 0; i < tabCount; i++){
View view = widget.getChildTabViewAt(i);
if (view != null){
TextView textView = (TextView)findViewById(R.id.title);
if (textView != null){
textView.setAllCaps(false);
textView.setSingleLine(true);
textView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
if (Build.VERSION.SDK_INT < 23){
textView.setTextAppearance(this, R.style.tab_appereance);
} else {
textView.setTextAppearance(R.style.tab_appereance);
}
textView.setTextSize(16);
}
}
}
}
}
}

Related

Raised center tab with newest TabLayout in android

I find older github use tabhost. github address
But tabhost is deprecated.
Is now can raised center tab with TabLayout?
You can try this code,its working for me:
My XML file:
<LinearLayout 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">
<TabHost
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffc916"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Android" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#da8200"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Iphone tab" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5b89ff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Windows tab" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Its my Activity file:
package com.example.sudiproy.tabproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends AppCompatActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost host = (TabHost) findViewById(R.id.tabHost);
host.setup();
//Tab 1
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("Android");
host.addTab(spec);
//Tab 2
spec = host.newTabSpec("Tab Two");
spec.setContent(R.id.tab2);
spec.setIndicator("Iphone");
host.addTab(spec);
//Tab 3
spec = host.newTabSpec("Tab Three");
spec.setContent(R.id.tab3);
spec.setIndicator("Window");
host.addTab(spec);
}
}

how play video on listview where on is focuses

I write application for android but have some problems
package com.example.test5.timeline;
import java.util.ArrayList;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.VideoView;
import com.example.test5.R;
import com.example.test5.testmsgActivity;
public class TimelineAdapter extends BaseAdapter {
private VideoView vv;
private TextView comment;
private LinearLayout video_layout, user_field, video_name_field,
users_info_field;
private int screen_w = 0, screen_h = 0;
private ImageView user_profile_image, google_plus;
Context ctx;
LayoutInflater lInflater;
ArrayList<SimplePost> posts;
TimelineAdapter(Context context, ArrayList<SimplePost> post) {
ctx = context;
posts = post;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
// кол-во элементов
#Override
public int getCount() {
return posts.size();
}
// элемент по позиции
#Override
public Object getItem(int position) {
return posts.get(position);
}
// id по позиции
#Override
public long getItemId(int position) {
return position;
}
// пункт списка
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// используем созданные, но не используемые view
View view = convertView;
if (view == null) {
view = lInflater
.inflate(R.layout.simple_post_layout, parent, false);
}
SimplePost p = getProduct(position);
screen_w = 1080;
screen_h = 1920;
comment = (TextView) view.findViewById(R.id.video_coment_count);
vv = (VideoView) view.findViewById(R.id.user_video);
vv.setVideoPath("http://server_ip/uploads/CAM00262.mp4");
vv.getLayoutParams().height = screen_w;
vv.getLayoutParams().width = screen_w;
video_layout = (LinearLayout) view.findViewById(R.id.video_layout);
video_layout.getLayoutParams().height = screen_w;
video_layout.getLayoutParams().width = screen_w;
user_field = (LinearLayout) view.findViewById(R.id.user_field);
video_name_field = (LinearLayout) view
.findViewById(R.id.video_name_field);
users_info_field = (LinearLayout) view
.findViewById(R.id.users_info_field);
google_plus = (ImageView) view.findViewById(R.id.video_plus_share);
user_profile_image = (ImageView) view
.findViewById(R.id.user_profile_image);
video_layout.getLayoutParams().height = vv.getLayoutParams().height;
video_layout.getLayoutParams().width = vv.getLayoutParams().height;
comment.setOnClickListener(
new View.OnClickListener()
{
#Override
public void onClick(View view)
{
vv.start();
}
}
);
return view;
}
public DisplayMetrics getScreenSize() {
testmsgActivity ttt = new testmsgActivity();
return ttt.getScreenSize();
}
SimplePost getProduct(int position) {
return ((SimplePost) getItem(position));
}
}
user_timeline_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/TimelinelistView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
simple_post.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/user_field"
android:layout_width="match_parent"
android:layout_height="50px"
android:orientation="horizontal" >
<ImageView
android:id="#+id/user_profile_image"
android:layout_width="50px"
android:layout_height="50px"
android:layout_marginLeft="10dp"
android:layout_marginTop="2px"
android:background="#drawable/photo" />
<TextView
android:id="#+id/user_profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Vahagn Vardanyan" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/video_name_field"
android:layout_width="match_parent"
android:layout_height="60px"
android:orientation="horizontal" >
<TextView
android:id="#+id/video_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:text="my first text video #first" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/video_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center" >
<VideoView
android:id="#+id/user_video"
android:layout_width="wrap_content"
android:layout_height="150px"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:id="#+id/users_info_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/video_view_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="view" />
<TextView
android:id="#+id/video_like_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="like" >
</TextView>
<TextView
android:id="#+id/video_coment_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="play_video"
android:text="comment" >
</TextView>
<ImageView
android:id="#+id/video_plus_share"
android:layout_width="match_parent"
android:layout_height="30px"
android:layout_weight="1"
android:src="#drawable/plus" />
</LinearLayout>
</LinearLayout>
where I insert post array on VistView (user_timeline_layout.xml) after press comment textview for play video, in this moment played all video . please help, how I can play video in x position or where in is focuses.

How to show tab title fully in android

I am newbie in android. I developed an android application that shows 15 tabs. One problem is i can't see each tab's title fully. Is it tabs in the android is scrollable.
I use below code to create tabs. looking for better solution
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="wrap_content"
>
<TabHost android:id="#android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent" android:id="#+id/linearLayout1" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="500px" android:id="#android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab1">
<TextView android:text="Tab1 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab2">
<TextView android:text="Tab2 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab3">
<TextView android:text="Tab3 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab4">
<TextView android:text="Tab4 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab5">
<TextView android:text="Tab5 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab6">
<TextView android:text="Tab6 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab7">
<TextView android:text="Tab7 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab8">
<TextView android:text="Tab8 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab9">
<TextView android:text="Tab9 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab10">
<TextView android:text="Tab10 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab11">
<TextView android:text="Tab11 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab12">
<TextView android:text="Tab12 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab13">
<TextView android:text="Tab13 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab14">
<TextView android:text="Tab14 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="#+id/tab15">
<TextView android:text="Tab15 Clicked" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
activity class
package mtx.samples;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class NewTabAppActivity extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final AlertDialog.Builder ad = new AlertDialog.Builder(this);
TabHost tabHost = getTabHost();
// tab1
TabSpec ts1 = tabHost.newTabSpec("Tab1");
ts1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.rss));
ts1.setContent(R.id.tab1);
tabHost.addTab(ts1);
// tab2
TabSpec ts2 = tabHost.newTabSpec("Tab2");
ts2.setIndicator("Tab 2");
ts2.setContent(R.id.tab2);
tabHost.addTab(ts2);
// tab3
TabSpec ts3 = tabHost.newTabSpec("Tab3");
ts3.setIndicator("Tab 3");
ts3.setContent(R.id.tab3);
tabHost.addTab(ts3);
// tab4
TabSpec ts4 = tabHost.newTabSpec("Tab4");
ts4.setIndicator("Tab 4");
ts4.setContent(R.id.tab4);
tabHost.addTab(ts4);
// tab5
TabSpec ts5 = tabHost.newTabSpec("Tab5");
ts5.setIndicator("Tab 5");
ts5.setContent(R.id.tab5);
tabHost.addTab(ts5);
// tab6
TabSpec ts6 = tabHost.newTabSpec("Tab6");
ts6.setIndicator("Tab 6");
ts6.setContent(R.id.tab6);
tabHost.addTab(ts6);
// tab7
TabSpec ts7 = tabHost.newTabSpec("Tab7");
ts7.setIndicator("Tab 7");
ts7.setContent(R.id.tab7);
tabHost.addTab(ts7);
// tab8
TabSpec ts8 = tabHost.newTabSpec("Tab8");
ts8.setIndicator("Tab 8");
ts8.setContent(R.id.tab8);
tabHost.addTab(ts8);
// tab9
TabSpec ts9 = tabHost.newTabSpec("Tab9");
ts9.setIndicator("Tab 9");
ts9.setContent(R.id.tab9);
tabHost.addTab(ts9);
// tab10
TabSpec ts10 = tabHost.newTabSpec("Tab10");
ts10.setIndicator("Tab 10");
ts10.setContent(R.id.tab10);
tabHost.addTab(ts10);
// tab11
TabSpec ts11 = tabHost.newTabSpec("Tab11");
ts11.setIndicator("Tab 11");
ts11.setContent(R.id.tab11);
tabHost.addTab(ts11);
// tab12
TabSpec ts12 = tabHost.newTabSpec("Tab12");
ts12.setIndicator("Tab 12");
ts12.setContent(R.id.tab12);
tabHost.addTab(ts12);
// tab13
TabSpec ts13 = tabHost.newTabSpec("Tab13");
ts13.setIndicator("Tab 13");
ts13.setContent(R.id.tab13);
tabHost.addTab(ts13);
// tab14
TabSpec ts14 = tabHost.newTabSpec("Tab14");
ts14.setIndicator("Tab 14");
ts14.setContent(R.id.tab14);
tabHost.addTab(ts14);
// tab15
TabSpec ts15 = tabHost.newTabSpec("Tab15");
ts15.setIndicator("Tab 15");
ts15.setContent(R.id.tab15);
tabHost.addTab(ts15);
ad.setTitle("NewTabApp");
ad.setNeutralButton("OK", null );
Button btnSendSettings = (Button)findViewById(R.id.btnSendSettings);
btnSendSettings.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send Settings button Clicked");
ad.show();
}
});
Button btnClose = (Button)findViewById(R.id.btnClose);
btnClose.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
System.exit(-1);
}
});
Button btnSave = (Button)findViewById(R.id.btnSave);
btnSave.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Save button Clicked");
ad.show();
}
});
Button btnSend = (Button)findViewById(R.id.btnSend);
btnSend.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
ad.setMessage("Send button Clicked");
ad.show();
}
});
}
}
you can make scrolling tabs in android using HorizontalScrollView in your layout xml file .
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</HorizontalScrollView>
For reference go through the link :
scrolling-tabs-android
Hope this will help you to solve your issue.

How to maintain multiple ListViews inside Tabhost

My question:
How do i view the lists for each tab separately? If I run it as is, when i select brooklyn, the same list from bronx displayed.
Another question. How do i make it so when i run the program, the list does not appear until you select whatever tab i choose.
package com.MTA_Transit;
import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
public class MTA_Transit extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
ListView bronx=(ListView)findViewById(R.id.bronx);
ListView brooklyn=(ListView)findViewById(R.id.brooklyn);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,BRONX);
bronx.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,BROOKLYN);
brooklyn.setAdapter(adapter);
//Bronx Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Bronx",getResources().getDrawable(R.drawable.tab_one))
.setContent(R.id.bronx));
//Brooklyn Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Brooklyn",getResources().getDrawable(R.drawable.tab_two))
.setContent(R.id.brooklyn));
//Manhattan Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Manhattan",getResources().getDrawable(R.drawable.tab_three))
.setContent(R.id.textview3));
//Queens Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Queens",getResources().getDrawable(R.drawable.tab_four))
.setContent(R.id.textview4));
//Staten Island Tab
mTabHost.addTab(mTabHost.newTabSpec("").setIndicator("Staten Island",getResources().getDrawable(R.drawable.tab_five))
.setContent(R.id.textview5));}
static final String[] BRONX = new String[] {
"Bx1 Grand Concourse","Bx2 Grand Concourse","Bx3 University Avenue/West 181 Street","Bx4","Bx4A","Bx5","Bx6","Bx7","Bx8","Bx9","Bx10","Bx11","Bx12","Bx13",
"Bx15 3 Avenue/125 Street","Bx16 East 233 Street/Nereid Avenue","Bx17","Bx18","Bx19","Bx20","Bx21","Bx22","Bx23","Bx24" ,"Bx26","Bx27"
};
static final String[] BROOKLYN = new String[] {
"Bx1 Grand Concourse"
};
}
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
<ListView android:id="#+id/bronx" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/brooklyn" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/list3" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<ListView android:id="#+id/list4" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
>
</ListView>
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
<TextView
android:id="#+id/textview5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="" />
</FrameLayout>
</LinearLayout>
</TabHost>
Each tab should have its own activity. Please see this tutorial. In each activity you will define its corresponding view separately, so you would have separate list views.

android tabwidget need help

Hello all this is my code for the tab layout in to android i want them in to bottom of the scrren currently it shows me at top of the screen
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" android:layout_alignParentBottom="true"
android:gravity="bottom">
<TabHost android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<HorizontalScrollView android:scrollbars="none"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TabWidget android:id="#android:id/tabs"
android:layout_alignParentBottom="true" android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
</LinearLayout>
tab.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#drawable/tab_background_selector" android:gravity="center"
android:orientation="vertical" android:padding="5dp"
android:layout_alignParentBottom="true" >
<ImageView android:id="#+id/tab_icon" android:layout_width="30dp"
android:layout_height="30dp" android:scaleType="fitCenter" />
<TextView android:id="#+id/tab_text" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="true"
android:textStyle="bold" android:gravity="center_horizontal"
android:textSize="10sp" android:padding="3dip" android:ellipsize="marquee"
android:textColor="#drawable/tab_text_selector"
android:layout_alignParentBottom="true" />
</LinearLayout>
this is my activity class
TestActivity.java
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabSpec;
public class TestActivity extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maiin);
final TabHost tabHost = (TabHost) getTabHost();
tabHost.addTab(createTab(MobiintheMorningActivity.class,
"Welcome", "Welcome", R.drawable.icon));
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
}
private TabSpec createTab(final Class<?> intentClass, final String tag,
final String title, final int drawable)
{
final Intent intent = new Intent().setClass(this, intentClass);
final View tab = LayoutInflater.from(getTabHost().getContext()).
inflate(R.layout.tab, null);
((TextView)tab.findViewById(R.id.tab_text)).setText(title);
((ImageView)tab.findViewById(R.id.tab_icon)).setImageResource(drawable);
return getTabHost().newTabSpec(tag).setIndicator(tab).setContent(intent);
}
}
here i've used android:layout_alignParentBottom="true" but no effects at all what should i do? what thing i am missing? thanks in advance :Pragna
See the solution to put the tab bar at the bottom.
Change the position of FrameLayout and widget in your xml.I think that my help you

Categories

Resources