I am trying to implement a premade library downloaded from a site to use it in my listview. It's called expandable listview, and I think we all know what that is.
In the XML file listview is like this:
<?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="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/text"
android:text="Hello World"/>
<!-- this is the button that will trigger sliding of the expandable view -->
<Button
android:id="#+id/expandable_toggle_button"
android:text="More"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/text"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/text"/>
</RelativeLayout>
<!-- this is the expandable view that is initially hidden and will slide out when the
more button is pressed -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/expandable"
android:background="#000000">
<!-- put whatever you want in the expandable view -->
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:text="Action A" />
<Button
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:text="Action B"/>
</LinearLayout>
</LinearLayout>
As we all know, an array list needs the listview to be just textview to work, otherwise it throws exception.
Can some one guide me how these things work on array list?
You can use custom adapter for this. See this link for tutorial on how to. :)
Related
<!-- test.xml -->
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/my_location_table_layout_results">
<ListView
android:id="#+id/button_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
<Button
android:id="#+id/fragmenttab1_item_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Help" >
</Button>
</FrameLayout>
I have not found example like this so not sure what I need to do is possible.
I need to open up a dialog that has multiple fragments and on one of those fragments have a textview with button that when the button is selected it
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableLayout
android:id="#+id/my_location_table_layout_results"
android:layout_width="match_parent"
android:layout_height="35dp"
android:stretchColumns="1"
android:shrinkColumns="0"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<EditText
android:id="#+id/fragmenttab1_item_edittext"
android:layout_width="0dp"
android:layout_weight="0.7"
android:gravity="center"
android:textSize="20sp"
android:layout_height="50dp" />
<Button android:layout_alignParentRight="true"
android:id="#+id/fragmenttab1_search_btn"
android:layout_width="0dp"
android:layout_weight="0.3"
android:layout_height="50dp"
android:gravity="top"
android:textSize="20sp"
android:text="Search"
style="WW3dBaseTheme" />
</TableRow>
</TableLayout>
<include
android:layout_width="match_parent"
android:layout_height="match_parent"
layout="#layout/test"
android:layout_below="#+id/my_location_table_layout_results" />
</RelativeLayout>
populates a listview of buttons that is shown below the textview/button on the same fragment.
Is that possible? I tried but for some reason instead of just the list of buttons I get copies of the textview/button pair and the button I want in the listview. It is almost as if because I have the listview in the xml it pulls in all the ui controls when it renders inside the listview. Here is the xml>
As I expected it turned out I needed to put the xml for control for the listview in another xml file in order to draw properly in the list.
I'm trying to get an image and a list in the same 'scroll' (I don't know how else to put it). My basic (vertical) layout is:
TextView
ImageView
ListView
I'm trying to get the scrolling as if the image is a list item itself. So the textview has to stay in place at the top and everything else has to scroll under it.
At the moment I have the following code:
<?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="#color/background"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/app_purple"
android:orientation="vertical" >
<TextView
android:id="#+id/about_app_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="15dp"
android:text="#string/about_app_label"
android:textColor="#color/background"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/app_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/logo" />
</LinearLayout>
<ListView
android:id="#+id/information_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background"
android:divider="#drawable/listdivider"
android:dividerHeight="1dp"
android:fadingEdge="none" >
<!-- Preview: listitem=#layout/row -->
</ListView>
Any help would be greatly appreciated!
EDIT
The custom row layout for the listView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/listview"
android:orientation="horizontal"
android:padding="4dip" >
<ImageView
android:id="#+id/list_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:layout_marginRight="5dp"
android:contentDescription="#string/icon_content_description" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/list_label"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:maxLines="1"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textColor="#color/result_label"
android:textStyle="bold" />
<TextView
android:id="#+id/list_count"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/list_label"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:textColor="#color/text" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/list_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#color/text"
android:textColorLink="#color/app_purple" />
<ProgressBar
android:id="#+id/list_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
You would have a vertical LinearLayout holding the fixed TextView and the ListView. Your ImageView would be a header on the ListView, added via addHeaderView(). Headers, despite their name, scroll with the contents of the ListView.
to make custom list views you need to create a single_list_item.xml file to arrange everything you want to scroll for example the image with a description text next to it. Also you need to add a ListView on your Xml file so the program can process the view. And them, you can process everything on your java file using an adapter. and the the list will appear at the bottom of the text.
There is a great example of how to do it here
it's not clear what exactly are you trying to do. ScrolView can have only ONE child. so I guess you should put the ImageView and the Listview in a LinearLayout.
but any way - it's a bad idea to put a Listview inside a ScrollView - how would the OS now what are you trying to scroll? the ListItem or the whole list. if you can be more specific - I can try help more...
I am new to this community as well as to android development.
For my study I need to make a (yes/no)questionnaire divided into 3 groups, some of the questions are quite long, so I want to make a part of it as big text and other part below as a small one.
I from tutorial on dev.and.com and made a TabLayout and for the moment I also have a LinearLayout for my questions
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_large"
android:textSize="16sp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_small"
android:textSize="12sp">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:gravity="right">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBxc">
</CheckBox>
</LinearLayout>
</LinearLayout>
Same is going to be for all of groups.
Code for tabLayout is like here
And AgroupActivity just displays a line of text right now (for testing purposes).
How can I make my layout to look like a list in each tab I have? Or maybe there are some other possibilities? As I understood, a simple ListView can't have anything(checkboxes in my case) in its tag?
You could use ListView to display a layout look like a list in each tabs.
With each tab content you use a ListView for each tab:
<?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" >
<ListView android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
And custom row (your_custom_row.xml) for each rows in ListView:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow
android:gravity="left"
>
<TextView
android:id="#+id/row_textview1"
android:textSize="25sp"
android:textStyle="bold"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:lines="1"/>
<TextView
android:id="#+id/row_textview2"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:paddingRight="10dp"
android:lines="1"/>
</TableRow>
</TableLayout>
and use Adapter to bind data to your ListView.
I have a custom list adapter inside of a TableLayout. This TableLayout is nested inside a of a LinearLayout.
The list adapter expands if new childviews are added to the list. I want the size of the TableRow to increase dynamically when the size of the list adapter increases. And the buttons pushed down when the list grows.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" android:layout_width="match_parent"
>
<LinearLayout">
<!-- Draw header + sub title -->
<LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" >
<TextView ></TextView>
<TextView ></TextView>
</LinearLayout>
<LinearLayout android:orientation="horizontal">
<ImageView />
<LinearLayout android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="1">
<TableLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1">
<TableRow android:id="#+id/tr1">
<CustomList android:id="#+id/mainview"
ndroid:layout_height="wrap_content" android:layout_width="wrap_content" />
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button android:layout_width="wrap_content" android:id="#+id/button1"
android:text="#string/buttonPrevious" android:layout_height="wrap_content">
</Button>
<Button android:layout_width="wrap_content" android:id="#+id/button2"
android:text="#string/buttonNext" android:layout_height="wrap_content"></Button>
</TableRow>
</TableLayout>
</LinearLayout>
<ImageView />
</LinearLayout>
</ScrollView>
Do I have to do change something like change the way layouts are inflated in my custom list adapter or anything else?
Please read the following question and answers. I believe this may be the same thing you are trying to achieve
Android ListView that does not scroll?
Hi all,
I'm a newbie to Android and having problems displaying items using a Linear layout and wondering if anyone can help me. The item list and pictures display fine but the textbox and search button are displayed for each item rather than getting displayed once. My code looks like:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"/>
<TextView
android:id="#+id/selection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/searchHeader"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/searchItem"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/search"
android:onClick="Search"/>
</LinearLayout>
</LinearLayout>
With this XML you should only see exactly one imageview and not a list of images as you discribed. Do you alter this layout programmatically in order do display various images? Maybe there you also add again the items you only want once.
Try moving the textview and search button outside of the linearlayouts they are in.