I am trying to insert a edit text box onto a tab - java

I am working on a android project and I have my four tabs. On one of the tabs, I am trying to insert an edit field box. ANy clues on how to do that?
Here is my main.xml file:
<?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">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="year of car" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a fourth tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
and here is my .java file:
package com.example.gasfillup;
import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class GasFillup 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();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Car Info").setContent(R.id.textview1));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Fillup Info").setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Gas Milage").setContent(R.id.textview3));
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Stats").setContent(R.id.textview4));
mTabHost.setCurrentTab(0);
}
}
Any Ideas or help is much appreciated!!
ironmantis7x

Wrap your with a ... so, framelayout, linearlayout, textview, edittext then close the linearlayout.
Well, let me edit that ... create a separate XML file to hold the entire view you want on the tab and then set it with R.layout.tab1 rather than setting tab1 to the textview.

As Bill Mote said, you need to wrap the content of the tab within some sort of container. Here's an example using a simple LinearLayout:
<?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">
<TextView
android:id="#+id/textview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="year of car" />
<TextView
android:id="#+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab" />
<TextView
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
<LinearLayout
android:id="#+id/panel4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textview4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="this is a fourth tab" />
<EditText
android:id="#+id/myeditfield"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Then change your code behind to:
....
mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Stats").setContent(R.id.panel4));
....
Realistically, this is how you should do all of the tabs (so that you can have more than just text), but you get the idea.

Related

How to switch between Activities in Android using only xml code

Hello I have a app im working on that I lost the source code to when my computer crashed I was able to decompile my apk to make it a project again however I need to make a few changes to it so what i need help with is this i have a sliding drawer that has a button in it I want it to open the play store when the user clicks it I know how to do this via a java activity however it only decompiled my code via smali code so I need to know if there is a way to open the play store from a button click via xml
here's my Main code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="#id/frame" android:focusable="true" android:focusableInTouchMode="true" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.d4a.tobiaslauncher.AnimationOnResume android:id="#id/animation_on_resume" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<com.d4a.tobiaslauncher.AnimationOpenFolder android:id="#id/animation_open_folder" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<LinearLayout android:gravity="center_horizontal" android:orientation="vertical" android:id="#id/folder_container" android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent">
<FrameLayout android:id="#id/folder_title_area" android:layout_width="fill_parent" android:layout_height="1.0dip" android:layout_marginLeft="7.0dip" android:layout_marginRight="7.0dip">
<EditText android:textSize="36.0dip" android:textColor="#ffffffff" android:gravity="center" android:layout_gravity="center_vertical" android:id="#id/folder_title" android:background="#drawable/folder_title" android:layout_width="fill_parent" android:layout_height="58.0dip" android:includeFontPadding="false" android:inputType="text" android:textCursorDrawable="#drawable/caret" />
<Button android:layout_gravity="right|center" android:id="#id/folder_title_clear" android:background="#drawable/folder_title_xbutton" android:layout_width="19.0dip" android:layout_height="19.0dip" android:layout_marginRight="16.0dip" />
</FrameLayout>
<net.suckga.ilauncher.paging.PageScrollView android:id="#id/folder_scroll_container" android:visibility="invisible" android:scrollbars="none" android:fadingEdge="none" android:layout_width="1.0dip" android:layout_height="1.0dip">
<LinearLayout android:orientation="horizontal" android:id="#id/folder_scroll_content" android:layout_width="wrap_content" android:layout_height="fill_parent" />
</net.suckga.ilauncher.paging.PageScrollView>
<com.d4a.tobiaslauncher.PageIndicator android:layout_gravity="bottom" android:id="#id/folder_page_indicator" android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="-17.0dip" />
</LinearLayout>
<RelativeLayout android:layout_gravity="top" android:id="#id/springboard_container" android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.d4a.tobiaslauncher.DockBar android:id="#id/dockBar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" />
<com.d4a.tobiaslauncher.PageIndicator android:id="#id/page_indicator" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="#id/dockBar" />
<net.suckga.ilauncher.paging.PageScrollView android:id="#id/scrollContainer" android:visibility="invisible" android:scrollbars="none" android:fadingEdge="none" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="#id/page_indicator">
<LinearLayout android:orientation="horizontal" android:id="#id/scrollView" android:layout_width="wrap_content" android:layout_height="fill_parent" />
</net.suckga.ilauncher.paging.PageScrollView>
<fragment android:name="com.d4a.tobiaslauncher.QuickLaunch"
android:id="#+id/quicklaunch"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="bottom"/>
</RelativeLayout>
<com.d4a.tobiaslauncher.MovingIconView android:id="#id/panelMoving" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="fill_parent" android:contentDescription="#null" />
<LinearLayout android:gravity="center" android:id="#id/logoPanel" android:background="#ff000000" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="#id/logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="#drawable/logo" android:contentDescription="#null" />
</LinearLayout>
</FrameLayout>
Sliding Drawer code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<SlidingDrawer android:id="#id/slidingDrawer" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="4.0dip" android:handle="#id/handle" android:content="#id/content">
<ImageView android:id="#id/handle" android:layout_width="fill_parent" android:layout_height="20.0dip" />
<LinearLayout android:orientation="vertical" android:id="#id/content" android:background="#color/drawerbg" android:layout_width="fill_parent" android:layout_height="wrap_content">
<include android:id="#id/web" android:layout_width="fill_parent" android:layout_height="72.0dip" android:layout_marginLeft="15.0dip" android:layout_marginTop="8.0dip" android:layout_marginRight="15.0dip" android:layout_marginBottom="8.0dip" android:onClick="web" layout="#layout/web_card" />
<include android:id="#id/mail" android:layout_width="fill_parent" android:layout_height="72.0dip" android:layout_marginLeft="15.0dip" android:layout_marginTop="8.0dip" android:layout_marginRight="15.0dip" android:layout_marginBottom="8.0dip" android:onClick="email" layout="#layout/email_card" />
<include android:id="#id/musiccard" android:layout_width="fill_parent" android:layout_height="72.0dip" android:layout_marginLeft="15.0dip" android:layout_marginTop="8.0dip" android:layout_marginRight="15.0dip" android:layout_marginBottom="8.0dip" android:onClick="music" layout="#layout/music_card" />
<include android:id="#id/playcard" android:layout_width="fill_parent" android:layout_height="72.0dip" android:layout_marginLeft="15.0dip" android:layout_marginTop="8.0dip" android:layout_marginRight="15.0dip" android:layout_marginBottom="8.0dip" android:onClick="play" layout="#layout/playstore_card" />
<include android:layout_gravity="center" android:id="#id/buttons" android:layout_width="wrap_content" android:layout_height="wrap_content" layout="#layout/buttons2" />
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Playstore Button card:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:background="#drawable/card_background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:onClick="play"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="#id/playicon" android:padding="5.0dip" android:layout_width="68.0dip" android:layout_height="68.0dip" android:src="#drawable/play" android:layout_centerVertical="true" />
<TextView android:textSize="30.0sp" android:textColor="#color/cardText" android:id="#id/play" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Google Play" android:layout_toRightOf="#id/playicon" android:layout_centerVertical="true" />
</RelativeLayout>
any help would be awesome
Thanks way in advance!!
You cannot do this with only XML code. You must create an OnClickListener or declare a onClick method and start the Activity in Java.
Maybe I'm misunderstanding your question. If so, I'm sorry, please let me know, and I'll change my answer.
But if you have a button and you want to go to a different activity it is very simple.
Simply add:
android:onClick="functionName"
to the XML of the button.
Then in your java, create a function called functionName that takes View view as a parameter and then create an intent to the new activity and start it.
public void functionName(View view) {
Intent intent = new Intent(getApplication(),classToGoTo.class);
startActivity(intent);
}
Or however else you want to go to that other activity. Or whatever else you want to do. Just put it inside of the functionName function.
I hope this helps. Good luck :)

Adding scroll in tabhost in android

I have a tab host in which i have more than 6 buttons. However the screen shows only 3-4 buttons.
Following is the code which i am using along with the image.
<?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"
android:background="#777777">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:id="#+id/layTab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#drawable/navbar_background"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#+id/layTab"/>
</RelativeLayout>
</TabHost>
The question is, How am i suppose to add a scroll so that i can scroll upto all 6 buttons or any other trick.
Best Regards
Just nest the TabWidget inside a HorizontalScrollingView, like this:
<?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"
android:background="#777777" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/layTab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:background="#drawable/navbar_background"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp" >
<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="wrap_content"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/layTab"
android:layout_alignParentTop="true" />
</RelativeLayout>
</TabHost>
By the way, this solution works for many other scenarios, RadioGroup, for example

Fragment Tab header/label size

I am sure it needs a simple flag but I am not finding the correct one, spent at least 2 hours to find a correct solution. Hope to get help from you guru's.
I am trying to create a two tab layout using fragmentActivity. I want to give 50% screen space to each tab. I am able to do that (see attached Screen shot) the next hurdle is I want the tab header e.g. Financial with black bkg should take 50% and Others with gary bkg to take remaining 50%.
I hope I am clear with my question. :-)
attaching my xml
<?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"
android:background="#EFEFEF" >
<RelativeLayout
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"
android:gravity="center_horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#+id/financial"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"
android:tag="#string/financial" />
<FrameLayout
android:id="#+id/other"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:tag="#string/others" />
</FrameLayout>
</RelativeLayout>
</TabHost>
**The calling xml would be**
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1" >
</ListView>
<fragment
class="com.......android.activity.AccountsTab"
android:id="#+id/tabs_fragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"/>
</RelativeLayout>
adding tab.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="#dimen/tab_height"
android:background="#drawable/tab_selector"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="#dimen/tab_padding"
android:weightSum="0.5" >
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal|center_vertical"
android:textColor="#drawable/tab_text_selector"
android:textSize="#dimen/text_default"
android:textStyle="italic" />
</RelativeLayout>
I think you should do it like this.
<?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">
<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"
>
<TabWidget
android:id="#android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="#+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</TabHost>
</LinearLayout>
With this you can add as many tabs as you want.
Hope you want this.

android get tabHost strip on top

I have tabHost positioned at bottom of view and tabHost strip appears also at bottom of taps. I would like to get strip positioned on top of tabs. How to do it? Here is my xml file. Thank you.
<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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</LinearLayout>
</TabHost>
Try With This..
<?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"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>

How to add an ActionBar above a TabWidget?

I am creating a custom bar above a TabHost. For some reason the custom bar does not appear above the TabHost, instead it is drawn behind it. Not sure why. Here is my XML:
<?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">
<!--
<RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="#+id/actionbarRelativeLayout">
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/icon" android:id="#+id/stocktwitsImageButton"></ImageButton>
<ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="#drawable/icon" android:id="#+id/composeImageButton" android:layout_alignParentRight="true"></ImageButton>
</RelativeLayout>
-->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<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"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Do not use TabHost as the root of your layout. Put your TabHost inside a LinearLayout with orientation:vertical.
Then inside the LinearLayout and before the TabHost, you can put your ActionBar.

Categories

Resources