ListView Complications - android

Because the information in each tab may not display depending on screen size, i have added a scrollview. The list view displays the information from the database alright but then it does not spread across the screen. It takes only a small portion of the screen and I can only scroll in that small portion. If i have 2 sets on information I expect to see two rows but I see just one and I can scroll within that to see the second set of information. But when i remove the scroll view my listview displays like it is supposed to but then the other tabs suffer because i cannot scroll to see the other fields.
Below is my main activity:
<TabHost
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"></TabWidget>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:fillViewport="true">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!--Overview Tab Starts-->
<LinearLayout
android:id="#+id/overviewTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/displayListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!--Overview Tab ends-->
<!--Base Data Tab starts-->
<LinearLayout
android:id="#+id/baseDataTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Base Data Tab ends-->
<!--Task Tab starts-->
<LinearLayout
android:id="#+id/taskTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Task Tab ends-->
<!--Survey Tab starts-->
<LinearLayout
android:id="#+id/surveyTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp">
//the needed views go here//
</LinearLayout>
<!--Survey Tab ends-->
</FrameLayout>
</ScrollView>
</LinearLayout>
</TabHost>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Overview Tab Starts -->
<LinearLayout
android:id="#+id/overviewTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/displayListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- Overview Tab ends -->
<!-- Base Data Tab starts -->
<LinearLayout
android:id="#+id/baseDataTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Base Data Tab ends -->
<!-- Task Tab starts -->
<LinearLayout
android:id="#+id/taskTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Task Tab ends -->
<!-- Survey Tab starts -->
<LinearLayout
android:id="#+id/surveyTab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp" >
</LinearLayout>
<!-- Survey Tab ends -->
</FrameLayout>
</ScrollView>
</LinearLayout>
You had some problems with your layout_height and width attributes. I changed some of them, this should work ;-)

Related

Is it possible to use Tabwidget on 2 rows

Currently i use TabWidget with 4 tabs on 1 Rows.
Each tab have a text description, not an icon.
I want to insert 1 or 2 Tabs more, but it's not possilbe on the rows because on small screen text description will be too small.
I wonder if a can add antoher tab row (just below the first row) with 1 or 2 tab inside?
My code is:
<TabHost android:id="#android:id/tabhost"
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"
android:dividerPadding="8dp"
android:scrollbars="horizontal" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="65dp" >
<!-- Tab 1 -->
<LinearLayout
android:id="#+id/tab_alimentation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
<!-- Tab 2 -->
<LinearLayout
android:id="#+id/tab_lance1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
<!-- Tab 3-->
<LinearLayout
android:id="#+id/linearLayout_tab_resultat"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp">
</LinearLayout>
<!-- Tab 4 -->
<LinearLayout
android:id="#+id/tab_lance2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
</LinearLayout>
</FrameLayout>
</TabHost>
Do you think it's possible,?
thx,

how to set scroll bar for tab host

i want to set scroll bar in tab host.in tab there is five tab but i want to display only three
tab at a time and how to make scrollbar for that so tab can be scroll for more tab...please provide me some solution.......
this is m xml file.....
<RelativeLayout
android:id="#+id/rl3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/gray" >
<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:gravity="center" >
<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="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
</RelativeLayout>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<fragment
android:id="#+id/fragment1"
android:name="info.tech.slidermenu.Home_feed"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment2"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment3"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment4"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
<fragment
android:id="#+id/fragment5"
android:name="info.tech.slidermenu.Upcoming_tennise_match"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="50dp" />
</FrameLayout>
</RelativeLayout>
</TabHost>
</RelativeLayout>
this is class file....
public void tabselect() {
TabHost tab = (TabHost) findViewById(R.id.tabhost);
tab.setup();
tab.setHorizontalScrollBarEnabled(true);
TabHost.TabSpec spec = tab.newTabSpec("tab1");
spec.setContent(R.id.fragment1);
spec.setIndicator("Feed");
tab.addTab(spec);
spec = tab.newTabSpec("tab2");
spec.setContent(R.id.fragment2);
spec.setIndicator("tennis");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment3);
spec.setIndicator("boxing");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment4);
spec.setIndicator("cricket");
tab.addTab(spec);
spec = tab.newTabSpec("tab3");
spec.setContent(R.id.fragment5);
spec.setIndicator("base ball");
tab.addTab(spec);
tab.setCurrentTab(0);
}
screen shot....
You're already using a HorizontalScrollView for the TabWidget, so this is the correct way. If you're not able to scrool despite doing is this way, probably you're having a layout problem.
You didn't detail if you're using a custom layout for your TabWidget, but if not, this would be a good approach to achieve what you want, since there's not a method to say "I just want to show 3 tabs at a time".
Simply define a new layout for your tabs so the three together fit the screen's width, the rest will be reachable by scrolling.
---- EDIT ----
I see pretty much LinearLayouts in your code. Try something like this:
<LinearLayout
android:id="#+id/TabContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="99"
android:orientation="vertical">
<TabHost
android:id="#+android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/TabLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<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>
<FrameLayout
android:id="#+android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" />
</LinearLayout>
</TabHost>
</LinearLayout>

Background a TabHost on Android

I have created a TabHost in main activity with 4 tab specs. I have set the background for the Tab host (drawable, png image) and made all activities in the tab specs to be transparent.
For example:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Dummy item to prevent EditText from receiving focus -->
<LinearLayout
android:focusable="true" android:focusableInTouchMode="true"
android:layout_width="0px" android:layout_height="0px"/>
<EditText android:id="#+id/etContactSearch"
android:layout_height="60dip"
android:layout_width="fill_parent"
android:drawableRight="#drawable/search_contact" >
</EditText>
<ListView android:id="#+id/lvContacts"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="1dp"
android:cacheColorHint="#00000000"
android:listSelector="#drawable/relative_layout_clickable">
</ListView>
</LinearLayout>
And one of the tab specs has some linear layouts and list activity:
<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="#drawable/bck_list">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp">
<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="0dp" />
</LinearLayout>
</TabHost>
When I start the application from Eclipse, the first time it runs, the background (#drawable/bck_list) is shown perfectly. But if I close the application and run it again, the background is missing (black color is showing instead).
What can be the problem here?
mTabHost.addTab(mTabHost
.newTabSpec("tab_1")
.setIndicator(g(R.string.TList))
.setIndicator(g(R.string.TList),
getResources().getDrawable(R.drawable.lis))
.setContent(new Intent().setClass(this, GList.class)));

Android textView scroll

I have been trying to develop an android app that contain an activity which is scrollable
and inside the activity, I have 2 textView which I want them to be scrollable as well.
My problem is that
whenever I touch inside the textView the scrolls show up but the main activity part which is the linearLayout directly steel the focus and no longer the textView scroll
the way I have it now is setup for the textView to scroll in the xml file I have done that.
and if I keep raising my finger and put it back on the screen trying to scroll the textView I can move a little bit but as I said, the layout that contains the textView capture the focus and leave me unable to scroll the textView.
I hope I did explain my problem very well.
Please any suggestion to help.
let me explain how the app is built first
first part is: the main(first) activity is a tabHost
which I defined as scrollable
<?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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</ScrollView>
</TabHost>
where I am having problem with is this activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/light_gray_color"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1"
android:orientation="vertical"
android:baselineAligned="false">
<LinearLayout
android:id="#+id/linearLayout3"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04">
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#color/black_color"
android:layout_gravity="center_horizontal"
android:text="#string/display_label"
android:id="#+id/display_label">
</TextView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.83"
android:baselineAligned="false"
android:orientation="horizontal" >
<ScrollView
android:id="#+id/english_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_english_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
<ScrollView
android:id="#+id/translation_scrollView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.03" >
<TextView
android:id="#+id/display_translation_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2px"
android:layout_marginRight="2px"
android:layout_weight="0.03"
android:background="#drawable/black_rectangle"
android:focusable="true"
android:paddingLeft="2px"
android:paddingRight="2px"
android:scrollbars="vertical"
android:textColor="#color/black_color" />
</ScrollView>
</LinearLayout>
</LinearLayout>
I guess you should cut <ScrollView> out of the first 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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="422dp" >
</FrameLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp" >
</TabWidget>
</LinearLayout>
</TabHost>
My understanding is that you have a vertically scrolling activity, which contains two vertically scrolling text views? If so, you can't do it. Its not just a poor design choice, its literally impossible to tell which view the user intends to scroll when they make swipe motion. You can have horizontal scrolling inside a vertically scrolling view, or vice versa. You can't have horizontal scrolling inside horizontal scrolling or vertical scrolling inside vertical scrolling.
I believe this is mentioned in the listview talk in the 2010 google io conference: http://www.youtube.com/watch?v=wDBM6wVEO70

Android + Bringing Tab to Front

I am using the following XML for tabs and this displays the tab at the bottom. However the tabs are being overlapped by the list and i cannot access any tab feature. The picture might be able to explain it better.
The list is draw over the tab. I appreciate any suggestions of bringing the tab to the front
XML:
![<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:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
>
<View android:layout_width="fill_parent" android:layout_height="0.5dip"
android:background="#000"/>
<TabWidget android:id="#android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="0dip" android:layout_marginRight="0dip"
android:layout_alignParentBottom="true"
/>
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#696969" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#000" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</RelativeLayout>
</TabHost>][1]
The solution for this is you have to set listview height so it will not overlap the tab at boot, just set fixed size for it.
<Listview
android:layoutheight="some fixed value">
If you are dynamically filling that then use
ln.setLayoutParams(new LayoutParams(width,height));

Categories

Resources