This is the .xml of the MainActivity, It's composed by two tabhost, the first contain a dynamic listview.
I want to add in the beginning of every item of listview an image like an icon or logo.
What are modifications of the .xml that i must do.
thx
this is main.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: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>
You can find a tutorial of using Custom ArrayAdapter with ListView: http://www.ezzylearning.com/tutorial.aspx?tid=1763429.
Here is another tutorial http://www.vogella.com/articles/AndroidListView/article.html.
Hope this helps.
You need to set up an adapter for your ListView and then in the getView of the adapter inflate or programmatically create a group of views that represents each individual item in the ListView.
You should google tutorials about how to set up adapters for ListViews
Related
Basically here is a mspaint demonstraiton of what I want to accomplish:
I do not want the outline to be visible to the user, it was just to give you an idea of what I want to do. I want new textviews to take position under each other whenever a new goal is added from the edittext-button combo on the bottom part of the GUI.
I know how to save the data - SQLite. But I have no idea how to make new textviews be on the bottom of the last one - and if there is no more room on the screen I want that textview part to be scrollable.
I don't know what I need to use to accomplish this.
Thanks in advance!
create two xml files.
One consisting of list view
<?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:orientation="vertical"
android:background="#drawable/bkgrnd_320x285">
<ListView
android:id="#+id/List1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#000000"
android:dividerHeight="1dp"
android:fastScrollEnabled="true"/>
</LinearLayout>
and another xml for just the textView eg. row.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="horizontal"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Name"
android:textSize="20dp"
android:layout_marginTop="20dp" />
</LinearLayout>
Then in the main activity u need to refer to both the xml files as follows
ListView ll = (ListView) findViewById(R.id.List1);
ArrayAdapter arrayAdapter = new ArrayAdapter(this,R.layout.row,R.id.textView2, arraylist_you_want_to_display);
ll.setAdapter(arrayAdapter);
where R.layout.row is the row.xml consisting of textView
And R.id.textView2 is the id of the textView present in the row.xml
You may create a LinearLayout, setting the orientation to vertical.
Adding a ScrollView or ListView to show the upper part, with android:weight=1
Add the EditText to the LinearLayout, and this is done.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/List1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:weight="1"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
i am new to android and had create the tabhost with two tabwidget all thing goes ok and fine and now i am displaying two different activity with two tab also.but the question is the text which i am specifying for two different tab is coming below while running the app.Below i am putting the screenshot for understanding
Screenshot:
the text are mark as red so is there any way to align that text to the center.
one more thing i m also using the drawable image for different state of user click.
thanks for any help.
the xml file for the tabhost
<?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"
>
<include layout="#layout/top_portion_layout"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
>
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#808080">
</FrameLayout>
</LinearLayout>
</TabHost>
the portion is another layout which having two button sync all and home
which i am including in this layout
inspite of
android:textAlignment="center"
you should use
android:gravity="center"
android:layout_gravity="center_vertical"
inside tab_host element
Im trying to manipulate the to do the following but its so far just lead to frustration... following is the poorly draw picture of what I am trying to accomplish:
http://i.stack.imgur.com/WZOta.png
http://i.stack.imgur.com/6cEQk.png
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="419dp" >
</ListView>
<TextView
android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/FAP001"
/>
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="+1" />
</LinearLayout>
</ScrollView>
Im not sure if the listview is the way to go.. heck im not even sure if linearlayout is a good call.. Im trying to have end result close to what is on the 2nd image.
THANKS IN ADVANCE!!!
You can't place an ListView within a ScrollView. Thats not possible. Because then the ListView has got two options to scroll trough the content, as you will. And this won't work.
For more Information:
https://groups.google.com/forum/m/?fromgroups#!topic/android-beginners/LRpLgGOy2Pc
If you want to have a ListView with 3 "sections" I would recommend you to create your own custom ListView with a Custom Adapter.
Here is a an Example of an custom ListView
http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/
You can just take this ListView and just have to modify the Adapter and the Row XML to your own needs.
Hi
I am an android user. I have content listing page and i completed it successfully. But the problem is i have to put two tab on the footer and the footer tab should remain permanently. I also done so many searches to fix this issue bu cannot find the solution. Anybody please help me.
Thanks,
Anoop
Do want to try to add header and footer to list view? then please check the addHeader in list view .check out this link
I have implement it,if need then i will post the code
You need to use a TabHost with the TabWidget underneath the FrameLayout inside a RelativeLayout instead of a LinearLayout, as follows
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:layout_alignParentTop="true"
android:id="#android:id/tabcontent"
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"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
I used the tabhost tutorial to get started with the Tabhost control.
After some play around I wanted to make the tabhost scrollable, which I figured out.
Now I want the tabhost at the bottom of the display which is just not working for me.
Switched to Relative Layout which was suggested here: iPhone-like Tabbar
My code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal" android:isScrollContainer="true">
<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:layout_alignParentBottom="true">
<RelativeLayout android:layout_height="fill_parent"
android:layout_width="fill_parent">
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:scrollbars="none"
android:layout_alignParentBottom="true">
<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="2dp" />
</RelativeLayout>
</TabHost>
I need a hint why it's not working / how this would work. I tried with relative layout and layout_alignParentBottom="true" now it's there a few times (in the HorizontalScrollView and the TabWidget)
Thanks to Arve leading me to "custom controls" I found a promising project:
https://github.com/honcheng/ScrollableTabHost-for-Android
I hope some others looking for this kind of tabhost can use it :)
A possible library to help you do this:
http://code.google.com/p/androidtabs/
From their project description:
Due to limitation of Android Tab component I created a custom TabWidget that I am using in couple different projects already. The widget allows us to add custom background and use custom icons, tabs can be Top/Bottom aligned.
EDIT: I have not tested this myself, but it looks promising.