I tried to search this question but no1 has answerd this, so here it is.
i am using a list view inside a scroll view.
when i am adding an onitemcliked listener to the listview it is not responding.
how to i get the listview access? i mean how do i get which position has been clicked. i know how it is normally done but inside a scroll view the listview is not reponding.
this is the code of adding onitemcliked listner to lisview.
itemlist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(cv, "position:"+arg2, Toast.LENGTH_SHORT).show();
}
});
here is the xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="2dp">
<TextView
android:id="#+id/et_agent_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Agent"
android:textStyle="italic" />
<TextView
android:id="#+id/login_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LoginId"
android:textSize="15dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Route" />
<Spinner
android:id="#+id/route_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<requestFocus />
</Spinner>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Shop" />
<TextView
android:id="#+id/tvShopName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tv_shopaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="italic"
android:text="Address : " />
<Button
android:id="#+id/button_no_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="No Order" />
</LinearLayout>
<TextView
android:id="#+id/et2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Product Details"
android:textSize="18dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="20dp"
android:src="#drawable/linedivider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etSearchBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
</EditText>
<Button
android:id="#+id/btn_SearchProduct"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Search" />
</LinearLayout>
<TableLayout
android:id="#+id/displayOrderTableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="1"
>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<Button
android:id="#+id/button_order"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Order"
android:textAlignment="inherit" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:src="#drawable/underline" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="#+id/button_clear"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Clear"
android:textAlignment="inherit" />
<Button
android:id="#+id/button_submit"
style="?android:attr/buttonStyleSmall"
android:layout_width="120dp"
android:layout_height="40dp"
android:text="Submit"
android:textAlignment="inherit" />
</LinearLayout>
</LinearLayout>
</ScrollView>
pleasde help me i am stuck on this.. it might be a very silly solution. but please help me
thank u in advance.
This is likely caused since that ScrollView is at higher level than the ListView in parent-child hierarchy. So that ScrollView can absorb touch events at its own level and does not pass them to its children. This results in the ListView will not get touch events at all and subsequently does not respond to onItemClicked.
The solution is here.
Related
I am trying to add an edittext above a listview. The edittext field gets displayed, however, it is repeated for each row in the listview as well, which I don't want.
I have tried placing it outside the first inner LinearLayout but there is no difference in the behaviour.
Can someone please help me to figure out what I might be doing wrong.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/llMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:orientation="vertical">
<EditText
android:id="#+id/searchString"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="#drawable/abc_ic_clear_holo_light"
android:ems="10"
android:hint="Search for..."
android:text="" >
</EditText>
<ListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:padding="3sp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvCategory"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingRight="1sp"
android:text=""
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvCategory"
android:paddingRight="1sp"
android:text=""
android:textColor="#000000"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView7"
android:paddingRight="1sp"
android:text=""
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="#+id/textView8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/textView5"
android:gravity="right"
android:paddingRight="1sp"
android:text=""
android:textColor="#000000"
android:textSize="16sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/idAdView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_weight="1"
android:orientation="vertical" />
</LinearLayout>
Try adding the edit text as header view to the list.
public void addHeaderView (View v)
Ref : http://developer.android.com/reference/android/widget/ListView.html#addHeaderView(android.view.View)
I have read through other posts. I can't able to find the solution still.
I tried putting
android:focusableInTouchMode="false"
android:focusable="false"
not worked.
I have included
android:clickable="true"
not worked.
In Java code, I have included
imgLeft.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
v.performClick();
}
}
});
aside with the onClickListener().
But still it didn't worked.
Here is my rough layout structure and position of the image view.
<RelativeLayout>
<FrameLayout>
<LinearLayout>
<Relativelayout>
<LineatLayout/>
<LinearLayout>
<LinearLayout>
<ImageView <--- This is the I needed to click.
android:id="#+id/imgLeft"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:src="#drawable/left"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</Relativelayout>
</LinearLayout>
</FrameLayout>
</Relativelayout>
I am using setOnClickListener for handling the click event.
imgLeft.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//some function here <-- **This function triggers only after the second click**
}
});
NOTE:
I thoroughly checked the other stackoverflow posts. But none of them solved the problem.. is there any solution for the above
UPDATE: Original code:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_image" >
<FrameLayout
android:id="#+id/layoutConfiguration"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/bg_image"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="#dimen/menu_header_height" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1" >
<LinearLayout
android:id="#+id/ll_menu"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="#dimen/menu_top_icon"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="5dp"
android:src="#drawable/menu" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.68"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Connect Bluetooths"
android:textColor="#fff"
android:textSize="#dimen/menu_tital_textsize" />
<!-- android:padding="#dimen/menu_tital_padding" -->
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".2"
android:gravity="center"
android:padding="15dp"
android:text=""
android:textColor="#fff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll_sole"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/tital_margin_top"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_leftBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgLeftBluetooth"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:src="#drawable/left" />
<TextView
android:id="#+id/tv_leftBluetooth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_rightBattery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="100%"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/holo_red_dark"
android:textSize="16sp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgRightBluetooth"
android:layout_width="wrap_content"
android:layout_height="#dimen/title_img_width"
android:layout_marginTop="5dp"
android:src="#drawable/right" />
<TextView
android:id="#+id/tv_rightBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:fontFamily="Raleway-Regular.ttf"
android:gravity="center"
android:text="Not Connected"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="#dimen/menu_tital_padding" >
<ToggleButton
android:id="#+id/toggleButton_connectBluetooth"
android:layout_width="#dimen/title_img_height"
android:layout_height="#dimen/title_text_height"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#drawable/toggle_selector"
android:checked="false"
android:padding="5dp"
android:text=""
android:textOff=""
android:textOn="" />
<TextView
android:id="#+id/tv_toggle_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="7dp"
android:text="Connect Left Bluetooths Only"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="#+id/fl_balloon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="-15dp"
android:gravity="center"
android:visibility="gone" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="#dimen/balloon_width"
android:layout_height="#dimen/balloon_height"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="#drawable/balloon" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="7dp"
android:fontFamily="Oswald-Regular.ttf"
android:gravity="center"
android:text="Pair"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:fontFamily="Oswald-Regular.ttf"
android:text="Configure Bluetooths"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="#dimen/menu_tital_textsize"
android:visibility="gone" />
<Button
android:id="#+id/btn_next"
android:layout_width="wrap_content"
android:layout_height="#dimen/menu_top_icon"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="29dp"
android:background="#drawable/button_box"
android:padding="3dp"
android:text="Continue"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</RelativeLayout>
The id of the clicks that were performed are
imgLeftBluetooth and imgRightBluetooth. These two imageviews were triggering only after 2nd click.
Its simple .You can try this
Just add android:onClick="clicking" in your ImageView (XML)
Then
public void clicking(View v)
{
Toast.makeText(v.getContext(),"Clicking On Image",Toast.LENGTH_LONG).show();
}
Edited
YOUR_IMAGE_VIEW_OBJ.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Do your Staff
}
});
Android ImageView's onClickListener does not work
I've made the next xml layout for listview item -
<?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="70dp"
android:background="#drawable/back_item"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_bot"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/tv_ico" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_saying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:singleLine="true"
android:text="blah blah"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:id="#+id/textView_nar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="sport"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/textView_clicks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#696969"
android:text="Clicks"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="#+id/button_add_item"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/add_state"
android:focusable="false" />
</LinearLayout>
</LinearLayout>
Well, when I'm using this xml layout and pressing on a listview item all is fine - the code gets into the onItemClick.
But when I adding to this layout an ImageButton I'm not able to get into the onItemClick function.
Here's the full layout code with the ImageButton -
<?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="70dp"
android:background="#drawable/back_item"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView_bot"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:src="#drawable/tv_ico" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/textView_saying"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:ellipsize="end"
android:singleLine="true"
android:text="blah blah"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="18sp" />
<TextView
android:id="#+id/textView_nar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="sport"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="15sp" />
<TextView
android:id="#+id/textView_clicks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:textColor="#696969"
android:text="Clicks"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="#+id/button_add_item"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dp"
android:background="#drawable/add_state"
android:focusable="false" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/clip_ico"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>
As you can see I've used android:focusable="false" but still not able to get into the onItemClick.
Any ideas why it happens?
Thanks for any kind of help
add android:descendantFocusability="blocksDescendants" in the root layout
enter code here
if you are suing custom Adpter for Listview
then
do it in you customadapter - getView method
ImageView YOURIMAGE=(ImageView) InflatedVIEW.findViewById(R.id.imageview1);
YOURIMAGE.setOnClickListener(new OnClickListener() {
#Override`
public void onClick(View v) {
}
In order to view all the elements inside my relativelayout in smaller screens, I have made the choice to use a scrollview to make it possible (or at least to try to accomplish this). The problem: I'm unable to scroll. The result of having or not the scrollview is the same, if the screen is small some elements will get cut off (this was fine if scroll was possible). In some searches I have come across some scrollview with linearlayout implementations, but in my case I think it's not very good, because i need check boxes aligned to the right of text.
Heres the xml of what I got thus far:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#231E1A"
android:keepScreenOn="true"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:ignore="ContentDescription"
android:fillViewport="true">
<RelativeLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="#string/btn_getDirections" />
<TextView
android:id="#+id/static_language"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/radioGroup"
android:layout_alignLeft="#+id/radioGroup"
android:text="#string/static_language"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_language"
android:layout_alignLeft="#+id/static_language"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_destination"
android:layout_alignLeft="#+id/aComplete_destination"
android:text="#string/static_destination"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_destination"
android:layout_alignLeft="#+id/static_destination"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_highways"
android:layout_alignLeft="#+id/static_highways"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/static_useCurrentLocation"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<TextView
android:id="#+id/static_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/aComplete_origin"
android:layout_alignLeft="#+id/aComplete_origin"
android:text="#string/static_origin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/static_origin"
android:layout_alignLeft="#+id/static_origin"
android:layout_alignParentTop="true"
android:paddingBottom="10dp"
android:scaleType="fitStart"
android:src="#drawable/logo" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/btn_getDirections"
android:layout_alignLeft="#+id/btn_getDirections"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
</RelativeLayout>
</ScrollView>
Huzzah! I got it to work! It was all a combination, of linearlayout, scrollview and relativelayout were was needed. Now it scrolls perfectly when the screen its not big enough to view the full content. I'm guessing that changing to linearlayout, was in fact the key in this. Basically i applied what was stated in developer site: http://developer.android.com/reference/android/widget/ScrollView.html
A child that is often used is a LinearLayout in a vertical
orientation, presenting a vertical array of top-level items that the
user can scroll through.
The xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#231E1A"
android:keepScreenOn="true"
android:scrollbars="none"
android:overScrollMode="never"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:ignore="ContentDescription"
android:fillViewport="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:keepScreenOn="true"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/logo"
android:scaleType="fitStart"
android:src="#drawable/logo"/>
<TextView
android:id="#+id/static_origin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_origin"
android:paddingTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<AutoCompleteTextView
android:id="#+id/aComplete_origin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_origin" >
<requestFocus />
</AutoCompleteTextView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/static_useCurrentLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingTop="10dp"
android:text="#string/static_useCurrentLocation" />
<TextView
android:id="#+id/static_tolls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/static_useCurrentLocation"
android:layout_below="#+id/static_useCurrentLocation"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/static_tolls" />
<TextView
android:id="#+id/static_highways"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/static_tolls"
android:layout_alignLeft="#+id/static_tolls"
android:paddingBottom="10dp"
android:text="#string/static_highways"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<CheckBox
android:id="#+id/tolls_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_tolls"
android:layout_alignBottom="#+id/static_tolls"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/highways_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_highways"
android:layout_alignBottom="#+id/static_highways"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
<CheckBox
android:id="#+id/useLocation_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/static_useCurrentLocation"
android:layout_alignBottom="#+id/static_useCurrentLocation"
android:layout_alignParentRight="true"
android:text="#string/checkbox" />
</RelativeLayout>
<TextView
android:id="#+id/static_destination"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_destination"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<AutoCompleteTextView
android:id="#+id/aComplete_destination"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions"
android:text="#string/aComplete_destination" />
<TextView
android:id="#+id/static_language"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/static_language"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio_english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:textColor="#FFFFFF"
android:layout_marginRight="20dp"
android:text="#string/radio_english" />
<RadioButton
android:id="#+id/radio_portugues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:text="#string/radio_portugues" />
</RadioGroup>
<Button
android:id="#+id/btn_getDirections"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/btn_getDirections" />
</LinearLayout>
</ScrollView>
I have implemented a ViewFlipper with 8 child view in my application as follows.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#drawable/main_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper
android:id="#+id/layout_tab_one"
android:layout_marginTop="70dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
layout="#layout/exterior_driverside_1"
/>
<include
layout="#layout/exterior_driverside_2"
/>
<include
layout="#layout/exterior_front_1"
/>
<include
layout="#layout/exterior_front_2"
/>
<include
layout="#layout/exterior_passenger_1"
/>
<include
layout="#layout/exterior_passenger_2"
/>
<include
layout="#layout/exterior_rear_1"
/>
<include
layout="#layout/interior_1"
/>
<include
layout="#layout/interior_2"
/>
<include
layout="#layout/interior_3"
/>
<include
layout="#layout/interior_4"
/>
<include
layout="#layout/interior_5"
/>
<include
layout="#layout/finalpage"
/>
</ViewFlipper>
</LinearLayout>
Each child layout resembles like this.
<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/check_title"
android:layout_marginTop="10dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:layout_marginRight="10dp"
android:textSize="18sp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Exterior / Rear "
/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greytop_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
>
<TextView
android:id="#+id/tailights_txt"
android:textColor="#ffffff"
android:text="Tailights"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/tailights"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true" />
<EditText
android:id="#+id/tailights_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/tailights"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/bootlid_txt"
android:textColor="#ffffff"
android:text="Boot lid / Tailgate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"/>
<CheckBox
android:id="#+id/bootlid"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/bootlid_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/bootlid"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/bumperbar_txt"
android:textColor="#ffffff"
android:text="Bumper Bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/bumperbar"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/bumperbar_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/bumperbar"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greymid_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/mudflaps_txt"
android:textColor="#ffffff"
android:text="Mud Flaps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/mudflaps"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/mudflaps_edit"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/mudflaps"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/greybott_bg"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp" >
<TextView
android:id="#+id/rear_unapproved_txt3"
android:textColor="#ffffff"
android:text="Unapproved advertising"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
/>
<CheckBox
android:id="#+id/rear_unapproved3"
android:checked="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"/>
<EditText
android:id="#+id/rear_unapproved_edit3"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_below="#+id/rear_unapproved3"
android:background="#drawable/edit_text"
android:hint="Tap to enter comments"
android:textSize="10dp"
android:visibility="gone"
/>
</RelativeLayout>
</LinearLayout>
I have implemented onGestureListener(onFling) to switch over another child view of the ViewFlipper. If i put ScrollView for each child view, onFling is not working. But every child view needs a scrollview. How to implement ScrollView in the ViewFlipper ? It will be greatfull if someone suggests some code for me.
Hope this helps you
#Override
public boolean dispatchTouchEvent(MotionEvent ev){
super.dispatchTouchEvent(ev);
return productGestureDetector.onTouchEvent(ev);
}
Yes, this really works. Textview scrolls automatically when overflow is there, if you don't handle the swipe gesture of view flipper adapter. So when you handle the swipe gesture yourself, make your textview scrollable by a adding
mTextView.setMovementMethod(new ScrollingMovementMethod());
And add the dispatchtoucheventfunction shown above, in your Activity.