checkbox'ed list on each tab - android

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.

Related

Android Development - Graphical Layout looks different from actual XML

Alright so I quickly created an XML file with the following contents:
<?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" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 1"
android:textSize="30dp" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 2"
android:textSize="30dp" />
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 3"
android:textSize="30dp" />
<ListView
android:id="#+id/listView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
And the question is, is that why does it look so much different when I click on the "Graphical Layout" tab? What I imagined the graphical layout to look like would basically be 3 labels right under each other (this is because I set everything to wrap content, and because there are no items inside either of the ListViews, so I'd think that it wouldn't even be visible). But anyway, the graphical layout shows it to be:
I'm not sure if that's correct or not, and if I run it will it look like I imagine it to look? I basically want (everything inside 1 ScrollView) 3 TextView's, and 1 ListView immediately following each TextView. So the layout will look like this:
ScrollView
TextView
ListView
TextView
ListView
TextView
ListView
End of ScrollView
Something exactly like the layout shown above. Could someone please tell me what is wrong within my XML file for all the other labels not be showing on it?
Note: When I click on the components on the side, it seems that a few things are shifting. (When I tried clicking on the TextView2 (to try to search for the blue bounds box) it seemed like the TextView1 label got pushed down a bit, and the second TextView was still not visible. If anyone could please help me achieve the layout that I want, it would be greatly appreciated.
EDIT: take a look at this approach.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 1"
android:textSize="30dp" />
</ScrollView>
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scrollView1">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 2"
android:textSize="30dp" />
</ScrollView>
<ScrollView
android:id="#+id/scrollView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scrollView2" >
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Text View 3"
android:textSize="30dp" />
</ScrollView>
</RelativeLayout>
As for the ListView you should not put a ListView inside a ScrollView. Here is an explanation of why you should not put a ListView inside a ScrollView: Listview inside ScrollView

Android - can't get scroll view to scroll the list correctly

I have this pretty basic view:
<?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"
>
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<EditText
android:id="#+id/question_text"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/submit"
android:layout_height="wrap_content"
android:text="#string/submit"
android:onClick="sendFeedback"
android:layout_width="fill_parent">
</Button>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
What I was hoping to do with it is to allow the user to scroll through the entire list of comments. As of now, when there are more comments then space on the screen, the screen does not scroll down.
Any idea what I should change to enable scrolling of the comments?
Thanks!
I would do away with the scrollview completely - based on what I THINK you're try to accomplish, since the listview will handle scrolling on its own. Like such:
<?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"
>
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: "
/>
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<EditText
android:id="#+id/question_text"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/submit"
android:layout_height="wrap_content"
android:text="#string/submit"
android:onClick="sendFeedback"
android:layout_width="fill_parent">
</Button>
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..."
/>
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/label"
android:textSize="20px" >
</ListView>
The difference now, is that the TextView with id "please_wait" will not scroll with the list. If you need it to scroll with the list, I would recommend using a dynamically built TableLayout in java for your list, then add that and your textview to a ScrollView. The TableLayout doesn't scroll on its own, and thats why its a better solution than using a ListView inside a ScrollView. If you want to do it this way, let me know and I will post some example code.
Seems like you're trying to add a header above your comments in the ListView. As coder noted, you shouldn't put a ListView in a ScrollView. You should look at adding a header view directly to your ListView (see addHeaderView).
basicly you can do like this:
get rid of scrollview and loading textview.
set a simple adaptor to your listview like this:
fList = (ListView)findViewById(R.id.lstview);
fList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new String[]{"Please wait while the discussion loads..."}));
Than get your comments and set to your listview.
list.setAdapter(adapter);
You should not have a ListView inside a ScrollView.
inflate a LinearLayout(vertical) instead:
<?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" >
<TextView
android:id="#+id/question_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Your question: " />
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<EditText
android:id="#+id/question_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/question_comment_hint"
android:inputType="textMultiLine"
android:lines="4" >
</EditText>
<Button
android:id="#+id/submit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="sendFeedback"
android:text="#string/submit" >
</Button>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Please wait while the discussion loads..." />
<LinearLayout
android:id="#+id/comments_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
In your code:
LinearLayout commentsLayout = (LinearLayout) findViewById(R.id.comments_layout);
To populate the LinearLayout:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(int i = 0; i < comments.size(); i++){
View childView = inflater.inflate(R.layout.comment_list_item, commentsLayout, false);
TextView comment = (TextView) childView.findViewById(R.id.comment);
comment.setText("Something");
categoriesLayout.addView(childView, i);
}
Something like that, hope this helps.

relative layout issues/android

I am having issues with creating a menu (not menu when you click menu button -- but menu as in the welcome screen to select items). I went to ImageView and TextView float (left/right) Android and I did not solve my issue. I would like to create at least five or six options to select from on this menu class. This is my menu.xml file. Please let me know what I need to do.
The issue is that the first item appears, but the second item overlaps the first item. I been picking away with this for the last hour and cannot solve this issue.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/icon" />
<TextView
android:textSize="18dp"
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site" />
<ImageView
android:src="#drawable/ic_menu_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
thannk you.
Why don't you use a LinearLayout (like a vertical one with severals little horizontal ones inside, each with a TextView and an ImageView) ?
Anyway, if you want to use RelativeLayout you should use something like android:layout_toRightOf, android:layout_toLeftOf, android:layout_above or android:layout_below in your xml to place your elements.
I advise you to take a look at http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html if you don't know those parameters.
You use a RelativeLayout but you don't place elements with reference to each other.
Example :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/topBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_centerHorizontal="true">
</Button>
<Button android:id="#+id/leftBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Left"
android:layout_below="#+id/topBtn"
android:layout_toLeftOf="#+id/topBtn">
</Button>
</RelativeLayout>
http://developer.android.com/reference/android/widget/RelativeLayout.html
A Linear Layout would be better.
Try this and tell me if this is what you needed:
<?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:padding="5dp"
android:orientation="vertical"
>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Check Your Account"
android:textSize="18dp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/message_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" View our Site"
android:textSize="18dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_menu_add" android:layout_gravity="center_horizontal"/>
</LinearLayout>
</LinearLayout>

Adding custom list adapter to a TableLayout

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?

Android. RadioButtons in a ListView

I have dynamically generated ListView, which consists radio-buttons as list items.
Is it possible to use radiogroup functionality in that listview or for these radiobuttons.
I mean, I'd like, that if the user select a radio button the radio button selected before would deselected.
That is my solution at the moment, which I don't like very much. I just save selected radio button and if another one will be selected, deselect the saved one.
Thank you for your suggestions or links.
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="#+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="#color/black"
android:background="#color/transparent_white"/>
<ListView
android:id="#+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
item.xml:
<?xml version="1.0" encoding="utf-8"?>
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rb_lineId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:paddingLeft="50dp"
android:background="#drawable/selector_custombutton"/>
But I also tried with this one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bg_tile"
android:padding="10dp">
<TextView
android:id="#+id/text_station_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TEST"
android:textColor="#color/black"
android:background="#color/transparent_white"/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/list_lines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
I think you want android:choiceMode="singleChoice". It's a bit tricky to implement (I don't know the exact specifics myself), but it's a starting point.

Categories

Resources