How i prevent automatic focus on create activity of scroll view - android

When activity is create the focus is automatic transfer on scroll view edit text box but i want to stop this process, i want when user touch on edit text box then focus transferred on scroll view.Pleas help me.
<?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"
android:background="#drawable/new_background"
android:descendantFocusability="afterDescendants">
<LinearLayout
android:id="#+id/ll_Login_ContentHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/new_background"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="#dimen/padding_top_bottom"
android:paddingLeft="#dimen/padding_left"
android:paddingRight="#dimen/padding_right"
android:paddingTop="#dimen/padding_top_bottom"
android:weightSum="1" >
<LinearLayout
android:id="#+id/ll_Login_Content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1" >
<ImageView
android:id="#+id/imgview_login_cabmapsLogo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".7"
android:scaleType="centerInside"
android:src="#drawable/new_cabmaps_logo" />
<ScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="200dip" >
<LinearLayout
android:id="#+id/ll_Login_Content1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".3"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="vertical" >
<EditText
android:id="#+id/Edtxt_Login_UserNm"
android:layout_width="match_parent"
android:layout_height="#dimen/Edtxt_height"
android:background="#color/new_EdtxtBg"
android:drawableLeft="#drawable/new_email"
android:drawablePadding="#dimen/drawable_padding"
android:cursorVisible="true"
android:gravity="left|center_vertical"
android:hint="#string/UserNm"
android:imeOptions="actionNext"
android:inputType="textPersonName|textNoSuggestions"
android:paddingLeft="#dimen/view_padding_left"
android:textSize="#dimen/textsize" />
<EditText
android:id="#+id/Edtxt_Login_Password"
android:layout_width="match_parent"
android:layout_height="#dimen/Edtxt_height"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:background="#color/new_EdtxtBg"
android:drawableLeft="#drawable/new_password"
android:drawablePadding="#dimen/drawable_padding"
android:gravity="left|center_vertical"
android:hint="#string/Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:paddingLeft="#dimen/view_padding_left"
android:textSize="#dimen/textsize" />
<LinearLayout
android:id="#+id/ll_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="#+id/btn_Login_NewUser"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_weight=".50"
android:background="#color/new_OrangeBtnColor"
android:text="SIGN UP"
android:textColor="#color/TextColor"
android:textSize="#dimen/btntextsize" />
<Button
android:id="#+id/btn_Login_login"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_marginRight="5dp"
android:layout_weight=".50"
android:layout_marginLeft="5dp"
android:background="#color/new_OrangeBtnColor"
android:text="LOGIN"
android:textColor="#color/TextColor"
android:textSize="#dimen/btntextsize" />
</LinearLayout>
<TextView
android:id="#+id/tv_OR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/new_or"
android:layout_marginTop="#dimen/Login_VerticalMargin"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/ll_Login_Content2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="horizontal"
>
<Button
android:id="#+id/loginViaFB"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:background="#drawable/new_fb"
android:onClick="onSocialMediaLoginClick"
android:tag="1"
android:layout_weight=".50"
/>
<Button
android:id="#+id/loginViaTwitter"
android:layout_width="match_parent"
android:layout_height="#dimen/btn_height"
android:layout_marginLeft="10dp"
android:background="#drawable/new_twitter"
android:onClick="onSocialMediaLoginClick"
android:tag="2"
android:layout_weight=".50"
/>
</LinearLayout>
<Button
android:id="#+id/btnForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#android:color/transparent"
android:text="#string/ForgotPassword"
android:layout_gravity="center_horizontal"
android:textColor="#android:color/background_light"
android:autoLink="all" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

<LinearLayout
android:id="#+id/ll_Login_Content1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".3"
android:layout_marginTop="#dimen/Login_VerticalMargin"
android:orientation="vertical" >
You can add this line in above layout android:focusableInTouchMode="true"

Related

Listview with EditText in each row , Scrollview inside FooterView of listview , adjustResize and adjustPan all working toghter

I have an one fragment in which I have ListView which has EditText in each row and inside footerview all controls are inside ScrollView when I set android:windowSoftInputMode="adjustPan" than it is not scroll my footerview form when softkeyboard open and also push up my header of activity and when I am trying to use android:windowSoftInputMode="adjustResize" it scroll footer view form but it auto scrolling my listview when any item open and lost EditText focus but my header is not move up.
Sorry I am not good in explaining but I hope any one undersatand what i want to explain. Actually i want to scroll scrollview to specific layout in footerview so that I face all these problems any one can help me ?
Thank You
Here is my fragment xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/application_background">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/card_list"
android:fadingEdgeLength="0dp"
android:scrollbars="none"
android:headerDividersEnabled="false"
android:descendantFocusability="afterDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:listSelector="#android:color/transparent"
android:footerDividersEnabled="false"
android:transcriptMode="alwaysScroll" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:id="#+id/ll_footer"
android:gravity="center"
android:background="#color/colorIndicatorFill">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pay 250"
android:textColor="#color/white"
android:id="#+id/txt_pay"
android:gravity="center"
android:textSize="#dimen/fontsize_txtview_18" />
</LinearLayout>
</LinearLayout>
Here is my footerView xml of listview
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fillViewport="true"
android:isScrollContainer="true"
android:id="#+id/scrollView">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ll_footer_card"
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:id="#+id/rl_or">
<TextView
android:id="#+id/txt_or"
android:textSize="#dimen/fontsize_txtview_16"
android:singleLine="true"
android:text="#string/or"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#color/colorActiveIndicator"/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_1"
android:layout_centerVertical="true"
android:paddingLeft="#dimen/size_10"
android:layout_toLeftOf="#id/txt_or"
android:background="#color/gray_light" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_1"
android:layout_centerVertical="true"
android:paddingRight="#dimen/size_10"
android:layout_toRightOf="#id/txt_or"
android:background="#color/gray_light" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/ll_choose_other_card">
<TextView
android:layout_width="0dp"
android:layout_weight="0.9"
android:layout_height="wrap_content"
android:text="#string/choose_other_card"
android:id="#+id/txt_add_new_card"
android:textSize="#dimen/fontsize_txtview_16"
android:textColor="#color/colorActiveIndicator"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radio_add_new_crad"
style="#style/RadioButton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/ll_card_detail_form">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<LinearLayout
android:layout_width="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/ll_scan_card"
android:layout_height="wrap_content"
android:background="#drawable/round_corner_light_green">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/cards"
android:id="#+id/iv_card"
android:scaleType="centerInside"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scan_card"
android:textSize="#dimen/fontsize_txtview_16"
android:textColor="#color/color_white"
android:id="#+id/txt_scan_card"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<View
android:layout_width="#dimen/size_300"
android:layout_gravity="center"
style="#style/DividerBottomLine"/>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edt_card_number"
android:hint="#string/hint_card_number"
android:singleLine="true"
android:digits=" 1234567890"
android:inputType="number"
android:maxLength="23"
android:textColor="#color/text_color"
android:textColorHint="#color/hint_color"
android:textSize="#dimen/fontsize_edttext"
android:background="#drawable/edt_background" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edt_expiry"
android:hint="#string/hint_expiry"
android:singleLine="true"
android:inputType="none"
android:imeOptions="actionNext"
android:textColor="#color/text_color"
android:textColorHint="#color/hint_color"
android:textSize="#dimen/fontsize_edttext"
android:background="#drawable/edt_background" />
<net.cachapa.expandablelayout.ExpandableLayout
android:id="#+id/expandable_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:el_duration="500"
app:el_expanded="false">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="#+id/ll_datePicker"
android:animateLayoutChanges="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/application_background"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layout_choose"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<kankan.wheel.widget.WheelView
android:id="#+id/wheel_month"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="#color/white"
android:layout_height="wrap_content" />
<kankan.wheel.widget.WheelView
android:id="#+id/wheel_year"
android:layout_width="0dp"
android:layout_weight="0.5"
android:background="#color/white"
android:layout_height="wrap_content" />
</LinearLayout>
<widget.RippleView
android:id="#+id/ripple_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
app:rv_centered="true"
app:rv_color="#color/white"
app:rv_type="simpleRipple" >
<TextView
android:id="#+id/txt_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/round_corner_light_green"
android:text="#string/btn_Done"
android:textColor="#color/color_white"
android:textSize="#dimen/fontsize_txtview_18" />
</widget.RippleView>
</LinearLayout>
</LinearLayout>
</net.cachapa.expandablelayout.ExpandableLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edt_cvv"
android:hint="#string/hint_cvv"
android:singleLine="true"
android:imeOptions="actionNext"
android:inputType="number"
android:maxLength="4"
android:textColor="#color/text_color"
android:textColorHint="#color/hint_color"
android:textSize="#dimen/fontsize_edttext"
android:background="#drawable/edt_background" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/edt_name_on_card"
android:hint="#string/hint_name_on_card"
android:singleLine="true"
android:maxLength="100"
android:textColor="#color/text_color"
android:textColorHint="#color/hint_color"
android:textSize="#dimen/fontsize_edttext"
android:imeOptions="actionDone"
android:background="#drawable/edt_background" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/chk_save_card"
android:textColor="#color/text_color"
style="#style/Checkbox"
android:textSize="#dimen/fontsize_edttext"
android:text="#string/save_card" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/size_10"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
You can try by removing the scrollview from the footer and adding it to the fragment, and then you can use a NonScrollableListView instead of ListView.
For more reference on how to use a NonScrollableListView use this:
Non-scrollable ListView inside ScrollView
PS: Hope you are using ViewHolders inside your adapter for the ListView.
Cheers!

Buttons are not shown in real device but shown in emulator in android

I have a linearlayout which has 2 buttons cancel & download which are use to cancel or download of image respectively. When I run the app on emulator [Emulator is Nexus-5] all works fine , these 2 buttons are shown, but when I test my app on real device [My device is samsung-core].
Image is loaded from internet and then this liearLayout is shown, initially it is hidden.
This is the screenshot from my device
And this is my emulator screenshot
This is layout file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
I am guessing this is happening because of Screen Height. But why this 2 buttons get hidden.What is making this weird thing happen in my layout file.
Thanks - Suraj
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightsum="10"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:padding="16dp"
android:weight="1"
>
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:weight="8"
>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
enter code here
Your imageview is match parent, so it cover the screen, use the above code. it will workl fine
try ScrollView. The Buttons may below your ImageView(and set your image view attr "wrap_content") or your layout.
demo below according your code:
<?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="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here" />
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/iv_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp">
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Because there is no space to show the button in the device. do as below
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:layout_above="#+id/linear_layout_download_cancel_button"
>
<EditText
android:id="#+id/et_pic_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter pic url here"/>
<Button
android:id="#+id/bt_pic_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send"/>
<ImageView
android:id="#+id/iv_pic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingTop="10dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_layout_download_cancel_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/bt_cancel_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>
<Button
android:id="#+id/bt_pic_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Download"/>
</LinearLayout>
</RelativeLayout>

Add multiple ListView lists in one single layout in Android

I am trying to add 3 or more lists in a layout xml. I didn't expect this to be a problem, but I don't see all the lists(and they get populated) and the view does not scroll. I need an opinion to what stupid stuff I am doing here, please.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/googleDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white" >
<RelativeLayout
android:id="#+id/navigationHeader"
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#drawable/wallpaper"
android:paddingTop="16dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/activity_horizontal_margin"
android:orientation="vertical" >
<EditText
android:id="#+id/searchTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search" />
<TextView
android:id="#+id/txtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_light"
android:text="Hello, user"
android:textColor="#android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_blue_light"
android:text="description"
android:textColor="#android:color/white" />
</LinearLayout>
</RelativeLayout>
<ScrollView
android:id="#+id/scrollojt"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/navigationHeader"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/activity_horizontal_margin" >
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:background="#1f000000" />
<TextView
android:id="#+id/questionsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/separator"
android:text="#string/questions_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/questionsTitle"
android:background="#android:color/holo_green_dark"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/appsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList"
android:text="#string/apps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/appsTitle"
android:background="#android:color/holo_red_dark"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/groupsTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList2"
android:text="#string/groupapps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/groupsTitle"
android:background="#android:color/holo_blue_bright"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
<TextView
android:id="#+id/dmTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/drawerList3"
android:text="#string/directapps_label"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<ListView
android:id="#+id/drawerList4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dmTitle"
android:background="#android:color/holo_green_light"
android:clickable="true"
android:focusableInTouchMode="true"
android:scrollbars="vertical" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Use just one ListView with an ArrayAdapter.
how to use arrayadapter
If you need help customizing the array adapter, just search on google or ask me ;)

How to modify layout to display input field when keyboard is shown?

I use the following layout
<?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="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
android:isScrollContainer="true">
<TextView
android:id="#+id/wizard4_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:scrollbars="vertical"
android:text="#string/wizard4_title"
android:textColor="#0088cc"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="#+id/wizard4_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text1"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_name"
android:hint="#string/wizard4_name_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/wizard4_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text3"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_address"
android:hint="#string/wizard4_address_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<Button
android:id="#+id/wizard4_btn_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_back" />
<Button
android:id="#+id/wizard4_btn_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_next" />
</LinearLayout>
</LinearLayout>
It is displayed as part of ViewAnimator:
viewAnimator = new ViewAnimator(this);
...
View step4 = View.inflate(getBaseContext(), R.layout.wizard4, null);
viewAnimator.addView(step4);
setContentView(viewAnimator);
When user clicks on the second input field (wizard4_address), soft keyboard is display, which hides the input field. Currently buttons wizard4_btn_next and wizard4_btn_back are also displayed when keyboard is shown, I don't need it. But I should keep them always at the bottom.
Try this. Hope you will get what you want.
<?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="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/wizard4_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:scrollbars="vertical"
android:text="#string/wizard4_title"
android:textColor="#0088cc"
android:textSize="20sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/wizard4_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text1"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/wizard4_name_hint" />
<TextView
android:id="#+id/wizard4_text3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:gravity="fill_horizontal"
android:scrollbars="vertical"
android:text="#string/wizard4_text3"
android:textSize="18sp" />
<EditText
android:id="#+id/wizard4_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/wizard4_address_hint" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/wizard4_btn_back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_back" />
<Button
android:id="#+id/wizard4_btn_next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/wizard_next" />
</LinearLayout>

Android: How to add a Button under a Button

Right now my xml looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<EditText
android:id="#+id/table"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:editable="false"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
</LinearLayout>
And I want to add a button right under my already created button. I tried adding another button, but it just puts it in the same line. is it the LinearLayout? if so, how do I fix this?
EDIT: Clarifications, I want my EditBox and Button to be in one line, followed by another EditBox and Button.
This is what you need then, and copy the entire inner LinearLayout to add more lines:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Copy from here -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
<!-- To herel, and paste under -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
</LinearLayout>
As for doing this using code, it is only if you are not aware of how many you need in total, otherwise, do it in XML.
Try this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
<EditText
android:id="#+id/table"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:editable="false"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/table
android:text="#string/copy"
android:onClick="copy"/>
<Button
android:id="#+id/button2"
android:layout_below="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/copy"
android:onClick="copy"/>
<EditText
android:id="#+id/table1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_toLeftOf="#id/tableButton"
android:hint="#string/table"
android:text="#string/table"
/>
<Button
android:id="#+id/secondButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tableButton"/>
<EditText
android:id="#+id/table2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:layout_bottom="#id/table1"
android:hint="#string/table"
android:text="#string/table"
/>
</RelativeLayout>
Try change your
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
into something like this
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/copy"
android:onClick="copy"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
.../>
</LinearLayout>
If you want the first button to have the same height as the editbox, then you will need to use Tablelayout.
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="#+id/table"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:editable="false"
android:hint="#string/table"
android:text="#string/table" />
<Button
android:id="#+id/tableButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="copy"
android:text="#string/copy" />
</LinearLayout>

Categories

Resources