Creating custom preference screen in android - java

I have created a PreferenceScreen(pref_screen.xml) for my settings menu. It contains list of objects with different categories. I have created another custom layout(settings.xml) containing buttons, views, texts, images.
I would like to know how can I display the contents of my custom layout in my PreferenceScreen.
This is my pref_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Flight Selection" >
<Preference
android:title="Change Flight"
android:selectable="true"
android:key="#string/choose_flight"
android:icon="#drawable/icon_select_flight" />
<Preference
android:title="Close Flight"
android:selectable="true"
android:key="#string/close_flight_successful"
android:icon="#drawable/icon_select_flight" />
</PreferenceCategory>
<PreferenceCategory
android:title="Terminal Panel" >
<Preference
android:title="Change Terminal"
android:selectable="true"
android:icon="#drawable/icon_terminal" />
</PreferenceCategory>
<PreferenceCategory
android:title="Printer Panel" >
<Preference
android:title="Choose Printer"
android:icon="#drawable/icon_printer" />
</PreferenceCategory>
<PreferenceCategory
android:title="AirFi Sync" >
<SwitchPreference
android:title="Enable Sync" />
<Preference
android:title="Sync Group"
android:icon="#drawable/airfi" />
<Preference
android:title="Sync Details"
android:icon="#drawable/airfi" />
</PreferenceCategory>
</PreferenceScreen>
And this is my settings.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/settings_content"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:weightSum="10" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="35dp"
android:id="#+id/relativeLayout3">
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/transparent"
android:layout_below="#+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/view" />
<Button
android:layout_margin="10dp"
android:id="#+id/select_flight_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:id="#+id/close_leg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_printer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_printer"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/choose_printer"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_print_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/configure_printer"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_printer"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/change_printer_format"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold" />
<Button
android:layout_margin="10dp"
android:visibility="visible"
android:id="#+id/configure_payment_device"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/white_button_bg_state_list"
android:drawableLeft="#drawable/icon_terminal"
android:maxHeight="#dimen/global_button_height"
android:minHeight="#dimen/global_button_height"
android:text="#string/change_payment_device"
android:textColor="#drawable/custom_text_color_for_buttons"
android:textSize="#dimen/button_text_size"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:textStyle="bold"
android:textSize="20sp"
android:text="Terminal Panel"
android:textColor="#color/adyen_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/close_leg"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/textView3" />
<TextView
android:textStyle="bold"
android:textSize="20sp"
android:text="Printing Panel"
android:textColor="#color/adyen_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/configure_payment_device"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/textView4" />
</RelativeLayout>
<View
android:id="#+id/divider_net_sales"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:background="#color/transparent" />
<RelativeLayout
android:id="#+id/ifs_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:gravity="bottom">
<View
android:id="#+id/divider_ifs_panel"
android:layout_width="match_parent"
android:layout_height="1dp"
android:visibility="gone"
android:background="#color/transparent" />
<TextView
android:id="#+id/sync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#id/divider_ifs_panel"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="#string/airfi_sync"
android:textSize="18sp"
android:visibility="gone"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>

set layout for Individual preferenceScreenusing this :
<Preference
android:title="#string/label_pref_version"
android:key="#string/pref_version"
android:layout="#layout/pref" />
After this Use findViewById to access element of customlayout.

Related

Edittext does not show keyboard On Click

I have a screen with four EditTexts, any edittext doesn't open the keyboard when I click on it. I'm not using an AVD, I'm using my own device, and tested in others devices and same result.My app has some activities like Login , sigup, home activity. In login and sigup activity edittext works correctly but in fragments of home activity keyboard is not opening.
XML
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="100dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="210dp"
android:background="#color/global_bg"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="18dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:src="#drawable/profile"
app:civ_border_color="#color/main_color"
app:civ_border_width="5dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_toEndOf="#+id/profile_image"
android:orientation="vertical">
<TextView
android:id="#+id/fullname_field"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="Muneeb Ur Rehman"
android:textColor="#color/black"
android:textSize="19sp" />
<TextView
android:id="#+id/city_field_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#+id/profile_image"
android:includeFontPadding="false"
android:text="user_city"
android:textSize="14sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-80dp"
android:padding="20dp">
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_margin="10dp"
android:layout_weight="1"
app:cardBackgroundColor="#color/main_color"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="#drawable/total_orders"
android:backgroundTint="#color/white" />
<TextView
android:id="#+id/totalOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="12"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/total_orders_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/totalOrders"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:includeFontPadding="false"
android:text="Total Orders"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="0dp"
android:layout_height="125dp"
android:layout_margin="10dp"
android:layout_weight="1"
app:cardBackgroundColor="#color/main_color"
app:cardElevation="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="#drawable/pending_orders"
android:backgroundTint="#color/white" />
<TextView
android:id="#+id/pendingOrders"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:fontFamily="#font/bungee"
android:includeFontPadding="false"
android:text="0"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:id="#+id/pendingOrders_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/pendingOrders"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:includeFontPadding="false"
android:text="Pending Orders"
android:textColor="#color/white"
android:textSize="18sp" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="19dp"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_person_black_24dp"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Name"
android:inputType="textPersonName"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_phone_iphone_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Mobile Number"
android:inputType="phone"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_location_city_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="City"
android:inputType="text"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<androidx.appcompat.widget.AppCompatEditText
android:id="#+id/user_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/profile_edittext_shape"
android:drawableLeft="#drawable/ic_baseline_location_on_24"
android:drawablePadding="10dp"
android:elevation="3dp"
android:hint="Address"
android:inputType="text"
android:padding="13dp"
android:textCursorDrawable="#drawable/cursor_color_edittext" />
<Button
android:id="#+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:background="#drawable/bg_btn"
android:fontFamily="#font/bungee"
android:text="UPDATE"
app:backgroundTint="#color/main_color" />
<Button
android:id="#+id/btnLogout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/bg_btn"
android:fontFamily="#font/bungee"
android:text="Logout"
app:backgroundTint="#color/main_color" />
</LinearLayout>
</LinearLayout>
</ScrollView>
```
Try using editText.setShowSoftInputOnFocus(true) and editText.setFocusable(true)
Also check your AndoridManifest.xml and add android:windowSoftInputMode="stateAlwaysVisible" to corresponding activity, or adjustResize.
<activity
android:name="com.fortrun.testcrashlytics.MainActivity"
android:windowSoftInputMode="adjustResize" >
</activity>
"adjustResize" The activity's main window is always resized to make
room for the soft keyboard on screen.
"stateAlwaysVisible" The soft keyboard is visible when the window receives input focus.

ImageButton over another image

Well, I recently see whatsapp and tinder application. The "change profile picture" option is the same besides the button over. How we can do this? Is there any lib? or shape to do this ?
Use this code :
<FrameLayout
android:gravity="center"
android:layout_centerInParent="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingBottom="24.0dip"
android:paddingLeft="0.5dip"
android:paddingRight="0.5dip"
android:paddingTop="35.0dip"
android:background="#ff26a69a"
xmlns:android="http://schemas.android.com/apk/res/android">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="178.0dip"
android:layout_height="178.0dip"
android:src="#drawable/ic_settings_profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
<ProgressBar
style="?android:attr/progressBarStyleInverse"
android:id="#+id/change_photo_progress"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="gone" />
<ImageButton
style="#style/ActionBarButtonStyle"
android:background="#drawable/input_circle"
android:elevation="2.0dip"
android:id="#+id/change_photo_btn"
android:layout_gravity="bottom|center|right"
android:layout_height="52.0dip"
android:layout_marginBottom="2.0dip"
android:layout_width="52.0dip"
android:src="#drawable/ic_cam_white" />
</FrameLayout>
in drawable folder
input_circle.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#drawable/input_circle_pressed" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="#drawable/input_circle_pressed" />
<item android:drawable="#drawable/input_circle_normal" />
</selector>
Output :
add textview inside of imageview
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearImage"
android:layout_weight="1"
android:gravity="center"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginTop="20dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imgtimer"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"
android:src="#drawable/downcounter"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true">
<TextView
android:id="#+id/txthourr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="2"
android:text="00"
android:layout_marginRight="3dp"
android:textColor="#color/white"
android:paddingRight="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="48dp"
/>
<TextView
android:id="#+id/txtcolon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLength="1"
android:text=":"
android:textColor="#color/white"
android:textSize="40dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="2dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtminutee"
android:maxLength="2"
android:textSize="48dp"
android:layout_marginLeft="4dp"
android:textColor="#color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="30"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txtsecc"
android:maxLength="2"
android:layout_marginLeft="4dp"
android:textSize="26dp"
android:textColor="#color/white"
android:layout_marginTop="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="00"
/>
</LinearLayout>
</FrameLayout>
Try this,alignEnd , alignRight , alignBottom the small image to the big image,and adjust the margin dimensions as per your images.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="right|center_vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/bigImage"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_width="140dp"
android:layout_height="140dp"
android:background="#drawable/back_image"/>
<ImageButton
android:id="#+id/small_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignEnd="#+id/big_mage"
android:layout_alignRight="#+id/big_image"
android:layout_alignBottom="#+id/big_image"
android:background="#drawable/small_image"
android:text="" />
</RelativeLayout>

Background colors don't appear on some android devices

in my application layout I have set custom colors in backgound but they don't appear on every android device. on some devices the background appears white instead of the colors I set. my app supports android 4 to 4.4
<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"
android:orientation="horizontal"
tools:context=".Volume" >
<TimePicker
android:id="#+id/ChoosenTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<View
android:id="#+id/view1"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/ChoosenTime"
android:background="#31B6E7" />
<ScrollView
android:id="#+id/horizontalScroll"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/view1"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical" >
<ToggleButton
android:id="#+id/sun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Sun"
android:textOn="Sun" />
<ToggleButton
android:id="#+id/mon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Mon"
android:textOn="Mon" />
<ToggleButton
android:id="#+id/tue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Tue"
android:textOn="Tue" />
<ToggleButton
android:id="#+id/wed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Wed"
android:textOn="Wed" />
<ToggleButton
android:id="#+id/thu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Thu"
android:textOn="Thu" />
<ToggleButton
android:id="#+id/fri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Fri"
android:textOn="Fri" />
<ToggleButton
android:id="#+id/sat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/togglebutton"
android:onClick="daysOfWeek"
android:textOff="Sat"
android:textOn="Sat" />
</LinearLayout>
</ScrollView>
<View
android:id="#+id/view2"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/horizontalScroll"
android:background="#31B6E7" />
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/horizontalScroll"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/sound"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onoff"
android:text="#string/sound" />
<RadioButton
android:id="#+id/vibrate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onoff"
android:text="#string/vibrate" />
<RadioButton
android:id="#+id/silent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onoff"
android:text="#string/silent" />
</RadioGroup>
<EditText
android:id="#+id/EventName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/horizontalScroll"
android:ems="10"
android:text="#string/event_name" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/ChoosenTime"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onoff"
android:text="#string/turn_on" />
<RadioButton
android:id="#+id/off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onoff"
android:text="#string/turn_off" />
</RadioGroup>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroup2"
android:layout_toRightOf="#+id/view2"
android:orientation="horizontal" >
<CheckBox
android:id="#+id/wifi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="checkBoxClicked"
android:text="#string/wifi" />
<CheckBox
android:id="#+id/bluetooth"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="checkBoxClicked"
android:text="#string/bluetooth" />
</LinearLayout>
<CheckBox
android:id="#+id/airplane"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_toRightOf="#+id/horizontalScroll"
android:onClick="checkBoxClicked"
android:text="#string/airplane_mode" />
</RelativeLayout>

how to set text right\left to my customAndroidView?

I want to create two rows of
TextView .... CustomeSwitvchView
CustomeSwitchView ... TextView
However, using this xml doesn't yield the expected order.
both rows show only the CustomeSwitchView aligned to right, with no text shown.
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
How can I fix this?
Try this:
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentTop="true"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:gravity="center_horizontal"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
Try this..
<LinearLayout style="#style/settingsSection">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection"
android:background="#drawable/item_selector_single"
android:layout_alignParentRight="true"
android:paddingLeft="85dp"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="wrap_content"
android:layout_below="#+id/settingsSwitchLayoutRtl"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection"
android:layout_alignParentLeft="true"
android:paddingRight="85dp"
android:background="#drawable/item_selector_single"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>
I am not sure but u can try it
<LinearLayout style="#style/settingsSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation = "vertical">
<RelativeLayout
android:id="#+id/settingsSwitchLayoutRtl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentRight="true"
android:id="#+id/settingsSwitchRtl" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/settingsSwitchRtl"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings1" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/settingsSwitchLayout"
android:layout_width="match_parent"
android:layout_below="#+id/settingsSwitchLayoutRtl"
android:layout_height="wrap_content">
<com.me.settings.SettingsSwitchView
style="#style/settingsSelection" android:background="#drawable/item_selector_single"
android:layout_alignParentLeft="true"
android:id="#+id/settingsSwitch" />
<TextView
android:id="#+id/switch_text"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/settingsSwitch"
android:layout_centerVertical="true"
android:textColor="#00FF00"
android:text="My Settings2" />
</RelativeLayout>
</LinearLayout>

Scrollview XML layout issue

Hoping this is a simple one.
I have a layout that uses a scrollview. This was fine until I wanted to put an image and textview above it then have the scrollview with my edittexts below it.
At the moment I'm getting the following errors:
01-22 20:13:32.228: E/AndroidRuntime(275): FATAL EXCEPTION: main
01-22 20:13:32.228: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.
I have tried to change the scroll views width attribute (which i believe that error is pointing too) with no luck.
Here's my XML. Can anyone see what I'm doing wrong?:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
\\ERROR: On width attribute
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</ScrollView>
</LinearLayout>
EDIT:
You can only set one child layout to a ScrollView. I don't know why it's showing you that you didn't set android:layout_width attribute, but your problem is definitely that you have multiple child views in your ScrollView.
<?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="84dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imgLink"
android:layout_width="78dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/viewcon" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="75dp"
android:gravity="center"
android:text="Appointments"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35sp" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Type:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TimePicker
android:id="#+id/timePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Appointment Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<DatePicker
android:id="#+id/datePicker1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/inputAppCom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Appointment Date Alarm:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ToggleButton
android:id="#+id/toggleButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ToggleButton"
android:textOff="Alarm Off"
android:textOn="Alarm On" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Appointment"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddAppointment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
</ScrollView>
</LinearLayout>

Categories