Using a CheckBox which doesn't exist in current layout - android

In my application i have a class named ChatActivity. Actually it is showing a ListView. In onCreate i have set the layout like
super.onCreate(savedInstanceState);
setContentView(R.layout.conversation_window);
conversation_window.xml looks like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:divider="#null"
android:padding="16dp"
android:fitsSystemWindows="true">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:id="#+id/thread_listView"
android:layout_below="#+id/editText"
android:layout_weight="1" />
<View
android:id="#+id/innerLine"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#9E9E9E"
android:layout_weight="0"
android:layout_marginBottom="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textStyle="bold"
android:textColor="#212121"
android:layout_marginBottom="8dp"
android:text="(1) 0/158"
android:id="#+id/character_count_textview"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0"
android:layout_marginBottom="10dp">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/compose_editText"
android:layout_weight="1"
android:layout_marginRight="5dp"
android:hint="এখানে লিখুন..."
android:inputType="textMultiLine|textCapSentences"
android:scrollbars="vertical"
android:background="#drawable/apptheme_textfield_disabled_holo_light"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="wrap_content"
android:id="#+id/send_imageButton"
android:background="#mipmap/send_black"
/>
</LinearLayout>
For each row of listView there is another xml called list_item_chat_message.xml which looks like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/CheckBox_conversation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="20dp"
android:visibility="gone" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/contentWithBackground"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#drawable/in_message_bg"
android:orientation="vertical">
<TextView
android:id="#+id/txtMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="200dp"
android:textColor="#android:color/black"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/timeInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="3dp"
android:textColor="#android:color/darker_gray" />
</LinearLayout>
There is a CheckBox in list_item_chat_message.xml which i want to use in my ChatActivity class for setOnCheckedChangeListener.But when i am writing like this in ChatActivity class
itemCheckBox = (CheckBox) findViewById(R.id.CheckBox_conversation);
it throws null object reference. So how i can i declare this CheckBox in this activity?

Related

Android XML Insert a layout on another layout

I am developing a screen that allows the user to create a post:
here
I want that when the user clicks on the cardview of the plus, a relative layout opens that through a recyclerview shows the various types of films, and the same thing for the other cardview with the genres of films. I don't know how to insert a layout into another layout and then use your own objects. What should I do, create an overlapping layout or do something else? I can't superimpose another layout on mine,
beacuse this happens
As you can see the related layout is below the main cardview. How could I put it on top?
Full Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".userProfile">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="-37dp"
android:backgroundTint="#EFE8AB"
app:cardCornerRadius="40dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtVal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Valutazione"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="230dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<androidx.cardview.widget.CardView
android:id="#+id/imBackReg"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="25dp"
android:layout_marginRight="8dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="60dp"
android:backgroundTint="#color/redButton2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_close_24"
/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descrizione:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="295dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<EditText
android:id="#+id/txt_desc"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginRight="20dp"
android:layout_marginTop="330dp"
android:background="#color/primaryPopHome2"
android:ems="10"
android:backgroundTint="#EFE8AB"
android:gravity="top|left"
android:hint="Descrizione"
android:layout_alignStart="#+id/txtVal"
android:inputType="textMultiLine"
android:textColor="#color/black"
android:textColorHint="#b7b7b7"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="450dp"
android:layout_marginHorizontal="15dp"
android:background="#color/darkpost"/>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="470dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txtT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tipologia:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginLeft="2dp"
android:layout_centerVertical="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:text="Tipologia scelta"
android:layout_marginTop="45dp"
android:layout_marginLeft="3dp"
/>
<androidx.cardview.widget.CardView
android:id="#+id/chooseTip"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="20dp"
android:layout_marginLeft="8dp"
android:layout_toEndOf="#+id/txtT"
android:layout_centerVertical="true"
android:backgroundTint="#color/darkpost">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_add_24"/>
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/txtC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categoria:"
android:layout_centerVertical="true"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginLeft="10dp"
android:layout_toEndOf="#+id/chooseTip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:text="Categoria scelta"
android:layout_marginTop="45dp"
android:layout_alignStart="#id/txtC"
android:layout_marginLeft="2dp"
/>
<androidx.cardview.widget.CardView
android:id="#+id/chooseCat"
android:layout_width="65dp"
android:layout_height="68dp"
app:cardCornerRadius="20dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/txtC"
android:backgroundTint="#color/darkpost">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/ic_baseline_add_24"/>
</androidx.cardview.widget.CardView>
</RelativeLayout>
</HorizontalScrollView>
<EditText
android:id="#+id/txt_valuta"
android:layout_width="50dp"
android:layout_height="46dp"
android:layout_marginTop="220dp"
android:layout_marginLeft="13dp"
android:layout_centerHorizontal="true"
android:background="#drawable/textview_new_style"
android:ems="10"
android:hint="0"
android:text=""
android:textSize="25dp"
android:textAlignment="center"
android:layout_toEndOf="#+id/txtVal"
android:textColor="#color/black"
android:textColorHint="#EFE8AB"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/10"
android:textSize="25dp"
android:textColor="#color/black"
android:layout_marginTop="225dp"
android:layout_marginLeft="5dp"
android:layout_toEndOf="#+id/txt_valuta"
/>
<androidx.cardview.widget.CardView
android:id="#+id/img_imgpost"
android:layout_width="140dp"
android:layout_height="150dp"
app:cardCornerRadius="30dp"
android:layout_marginLeft="20dp"
android:layout_alignParentTop="true"
android:layout_marginTop="50dp"
android:backgroundTint="#color/darkpost">
<ImageView
android:id="#+id/imgPostICV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#color/darkpost"/>
</androidx.cardview.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Titolo:"
android:textColor="#color/black"
android:fontFamily="#font/amiko"
android:textSize="25dp"
android:layout_marginTop="567dp"
android:layout_alignStart="#+id/img_imgpost"
/>
<EditText
android:id="#+id/txt_titoloo"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="600dp"
android:layout_marginHorizontal="5dp"
android:backgroundTint="#color/darkpost"
android:ems="10"
android:hint="Titolo"
android:layout_marginBottom="20dp"
android:inputType="textEmailAddress"
android:textColor="#color/black"
android:textColorHint="#b7b7b7"
android:layout_alignStart="#+id/d"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="#+id/btn_invia"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="660dp"
app:cardCornerRadius="15dp"
android:layout_marginBottom="10dp"
android:layout_marginHorizontal="20dp"
android:backgroundTint="#E8E1A2"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pubblica il Post"
android:textColor="#color/black"
android:layout_centerInParent="true"
android:textSize="30dp"
android:fontFamily="#font/amiko"
android:textStyle="bold"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"/>
</RelativeLayout>
This example could solve your problem
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include
android:id="#+id/innerLayout"
layout="#layout/inner_layout" />
</RelativeLayout>
inner_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="top_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="inner text" />
</RelativeLayout>
Now in your MainFragment class
Depending on your need you can set the visibility of the inner_layout by using the following code snippet
View innerLayout = findViewById(R.id.innerLayout);
//For hiding the innner layout dynamically
innerLayout.top_layout.setVisibility(View.GONE);
//For showing the innner layout dynamically
innerLayout.top_layout.setVisibility(View.VISIBLE);
//to set text in TextView
innerLayout.text.setText("Anything you want");

How to add time slot in recyclerview android

I have recyclerview a and all times will be displayed. I want to display slot type. should i use any library to code layout like that? or we can do in our xml itself.
please someone suggest me
activity_booking_calender.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_large"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="Select Date & Time"
android:textColor="#color/black_updated"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/startdate_enddate_text_margin_top"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/relative_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_gravity="start|center"
android:gravity="start|center"
android:orientation="vertical"
android:layout_alignParentLeft="true">
<TextView
android:layout_marginLeft="20dp"
android:id="#+id/txt_start_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/startdate_enddate_text_margin_bottom"
android:fontFamily="#font/inter_regular"
android:gravity="center"
android:text="START TIME"
android:textColor="#color/text_grey"
android:textSize="#dimen/startdate_enddate_text"
android:textStyle="bold" />
<LinearLayout
android:layout_marginLeft="20dp"
android:id="#+id/linear_start_date"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_start_date"
android:background="#drawable/btn_grey_background_no_stroke"
android:orientation="horizontal"
android:paddingTop="#dimen/motorcycle_date_text_top"
android:paddingBottom="#dimen/motorcycle_date_text_bottom">
<ImageView
android:layout_width="#dimen/motorcycle_date_icon_width"
android:layout_height="#dimen/motorcycle_date_icon_height"
android:layout_gravity="center"
android:layout_marginStart="#dimen/motorcycle_date_icon_start"
android:src="#drawable/ic_calendar_white"
android:layout_marginLeft="#dimen/motorcycle_date_icon_start" />
<TextView
android:id="#+id/txt_select_from_date"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="#dimen/motorcycle_date_text_start"
android:layout_marginEnd="#dimen/motorcycle_date_text_end"
android:fontFamily="#font/inter_regular"
android:gravity="center"
android:lineSpacingExtra="14.0sp"
android:text=""
android:textColor="#ffffffff"
android:textSize="#dimen/motorcycle_date_text"
android:layout_marginRight="#dimen/motorcycle_date_text_end"
android:layout_marginLeft="#dimen/motorcycle_date_text_start" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relative_end_date"
android:layout_width="wrap_content"
android:clickable="true"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:layout_gravity="end|center"
android:gravity="end|center"
android:orientation="vertical">
<TextView
android:id="#+id/txt_end_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="#dimen/startdate_enddate_text_margin_bottom"
android:fontFamily="#font/inter_regular"
android:gravity="center"
android:text="END TIME"
android:textColor="#color/text_grey"
android:textSize="#dimen/startdate_enddate_text"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_end_date"
android:background="#drawable/btn_grey_background_no_stroke"
android:orientation="horizontal"
android:paddingTop="#dimen/motorcycle_date_text_top"
android:paddingBottom="#dimen/motorcycle_date_text_bottom">
<ImageView
android:layout_width="#dimen/motorcycle_date_icon_width"
android:layout_height="#dimen/motorcycle_date_icon_height"
android:layout_gravity="center"
android:layout_marginStart="#dimen/motorcycle_date_icon_start"
android:src="#drawable/ic_calendar_white"
android:layout_marginLeft="#dimen/motorcycle_date_icon_start" />
<TextView
android:id="#+id/txt_to_date"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="#dimen/motorcycle_date_text_start"
android:layout_marginEnd="#dimen/motorcycle_date_text_end"
android:fontFamily="#font/inter_regular"
android:gravity="center"
android:lineSpacingExtra="14.0sp"
android:text=""
android:textColor="#ffffffff"
android:textSize="#dimen/motorcycle_date_text"
android:layout_marginLeft="#dimen/motorcycle_date_text_start"
android:layout_marginRight="#dimen/motorcycle_date_text_end" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/txt_time_select"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="3dp"
android:gravity="center"
android:lineSpacingExtra="14.0sp"
android:padding="7.0dip"
android:text="Please Select the Minimum booking of 2 hours"
android:textAlignment="center"
android:textColor="#ff4e44d8"
android:textSize="14dp"
/>
<com.prolificinteractive.materialcalendarview.MaterialCalendarView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/calendarView"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_below="#+id/linear_time_type"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_margin="#dimen/margin_small"
android:layout_weight="0.5"
app:mcv_allowClickDaysOutsideCurrentMonth="true"
app:mcv_arrowColor="#7EA2FA"
app:mcv_selectionColor="#ff4e44d8" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1.0dip"
android:layout_below="#+id/calendarView"
android:background="#color/divider" />
<RelativeLayout
android:id="#+id/relative_list_time_slots"
android:layout_width="fill_parent"
android:layout_height="0.0dip"
android:layout_below="#+id/divider"
android:layout_weight="0.5">
<LinearLayout
android:id="#+id/linear_progress_wave"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/txt_pick_drop_RR"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt_pick_up_drop"
android:text="Select Pick Up Time"
android:gravity="center"
android:textColor="#ff4e44d8"
android:textSize="16dp"
android:fontFamily="#font/inter_medium"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TextView>
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_below="#+id/txt_pick_drop_RR"
android:id="#+id/recyclerView_timeSlots"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginEnd="#dimen/margin_small"
android:layout_marginBottom="50.0dip"
android:scrollbars="horizontal"
android:visibility="visible" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView_timeSlots_next"
android:layout_below="#+id/txt_pick_drop_RR"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginEnd="#dimen/margin_small"
android:layout_marginBottom="50.0dip"
android:scrollbars="horizontal"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/layout_actionbtns"
android:layout_margin="5.0dip"
android:gravity="bottom|center|right"
android:text="Indian Standard Time"
android:textColor="#color/light_gray"
android:textSize="10.0dip" />
<LinearLayout
android:id="#+id/layout_actionbtns"
android:layout_width="fill_parent"
android:layout_height="#dimen/common_btn_height"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<LinearLayout
android:layout_marginLeft="10dp"
android:id="#+id/btn_cancel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="#drawable/ripple_next_button"
android:clickable="true"
android:foreground="#drawable/ic_ripple_white"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:layout_width="17.0dip"
android:layout_height="17.0dip"
android:layout_gravity="center"
android:src="#drawable/ic_wrong" />
</LinearLayout>
<TextView
android:id="#+id/txt_cancel"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginLeft="10.0dip"
android:gravity="center"
android:text="Cancel"
android:textColor="#color/white"
android:textSize="18.0dip"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="10.0dip"
android:layout_height="fill_parent"
android:background="#color/white" />
<LinearLayout
android:layout_marginRight="10dp"
android:id="#+id/btn_done"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight="0.5"
android:background="#drawable/ripple_next_button"
android:clickable="true"
android:foreground="#drawable/ic_ripple_white"
android:focusable="true"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:layout_width="20.0dip"
android:layout_height="20.0dip"
android:layout_gravity="center"
android:src="#drawable/ic_tick" />
</LinearLayout>
<TextView
android:id="#+id/txt_done"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginLeft="10.0dip"
android:layout_marginRight="16.0dip"
android:fontFamily="#font/inter_medium"
android:gravity="center"
android:minHeight="0.0dip"
android:paddingStart="10.0dip"
android:paddingEnd="10.0dip"
android:text="NEXT"
android:textColor="#color/white"
android:textSize="16.0sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Here my Recycler view xml file. i guess we have to modify here to get layout like time slots.
but not sure how to make.
time_slot_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:background="?android:attr/selectableItemBackground"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:textAlignment="center"
android:textSize="20dp"
android:id="#+id/time_slot"
android:layout_height="35dp">
</TextView>
It's up to UX you want to achieve. Plus you don't need any external library to achieve this UX.
In this case, you can use the default Number Picker.
In XMX :
<NumberPicker
android:id="#+id/slot_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
In Acivity :
private NumberPicker picker1;
#Override.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picker1 = findViewById(R.id.numberpicker_main_picker);
}
A NumberPicker takes an array of Strings as its values. First, create an instance variable of a string array, then initialize the array with your desired values.
private String[] pickerVals;
pickerVals = new String[] {"slot 1","slot 2","slot 3","slot 4","slot 5"}
picker1.setDisplayedValues(pickerVals);
Number Picker
Refered from this Example
You may make use of Android native widget - NumberPicker. This allows you to pick a number from a predefined range.
https://stackoverflow.com/a/39662187/5742882
For dynamic updation,
take a gist of https://github.com/drawers/SpinnerDatePicker.
This also makes use of NumberPicker with proper date formattings.

Layout_height doesn't want to gradually wrap contents when fragment are being used

What i want to accomplish is to create rating section like Google Play Store, i managed to display all the stars and review(for user to comment) but whenever the user type on it, the layout height of the RelativeLayout on my activity doesn't wrap the layout of the fragment within a fragment. I tried changing the height in any means, but still nothing solve the problem. The thing is when i make my TabLayout visible, it follows the height, but not my custom ViewPager.
I do not know whether i did it right or wrong or entirely impossible, please show me the right way. Thank you.
activity_view_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hybridelements.recyclerview.ViewItem">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/singleImageView"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="29dp"
app:srcCompat="#drawable/android" />
<TextView
android:id="#+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lblTitle"
android:layout_alignBottom="#+id/itemName"
android:textSize="16sp"
android:layout_marginLeft="25dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="#string/itemName"
android:textSize="16sp"
android:layout_below="#+id/singleImageView"
android:layout_alignStart="#+id/singleImageView"/>
<TextView
android:id="#+id/lblCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lblCategory"
android:layout_alignTop="#+id/itemCategory"
android:layout_alignStart="#+id/lblTitle"
android:layout_marginRight="30dp"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="#+id/itemCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/itemCategory"
android:textSize="16sp"
android:layout_below="#+id/itemName"
android:layout_alignStart="#+id/singleImageView"
android:layout_marginTop="14dp" />
<TextView
android:id="#+id/lblRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/lblCategory"
android:layout_below="#+id/lblCategory"
android:layout_marginTop="13dp"
android:text="#string/lblRating"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/itemRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/lblRating"
android:layout_alignStart="#+id/singleImageView"
android:text="#string/itemRating"
android:textSize="16sp" />
<ImageView
android:id="#+id/imageRating"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_alignBottom="#+id/itemRating"
android:layout_alignTop="#+id/itemRating"
android:layout_gravity="center"
android:layout_toEndOf="#+id/itemRating"
android:layout_marginLeft="5dp"
app:srcCompat="#drawable/star" />
<TextView
android:id="#+id/lblDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="13dp"
android:text="#string/lblDesc"
android:textSize="16sp"
android:textStyle="bold"
android:layout_alignStart="#+id/itemDesc"
android:layout_below="#+id/itemRating"/>
<TextView
android:id="#+id/itemDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/lblDesc"
android:layout_centerHorizontal="true"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="13dp"
android:text="#string/itemDesc"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/ratingSection"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/itemDesc"
android:background="#color/ratingSection">
<!-- Get section from fragment -->
</RelativeLayout>
<RelativeLayout
android:id="#+id/subTab"
android:layout_width="match_parent"
android:layout_height="511.84dp"
android:layout_marginTop="13dp"
android:layout_below="#+id/ratingSection">
<!-- Get section from fragment -->
</RelativeLayout>
</RelativeLayout>
</ScrollView>
fragment_sub_section_rating.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.SubSectionFragment_ReviewAndInstructions">
<RelativeLayout
android:id="#+id/main_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="6dp"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:visibility="gone"/>
<com.hybridelements.openchef.fragment_activities.fragment_subs.CustomSubViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tab_layout"/>
<com.pixelcan.inkpageindicator.InkPageIndicator
android:id="#+id/fragRating_dotIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:dotDiameter="8dp"
app:dotGap="8dp"
app:animationDuration="320"
app:pageIndicatorColor="#android:color/darker_gray"
app:currentPageIndicatorColor="#android:color/black"
android:layout_alignBottom="#+id/pager"
android:layout_marginBottom="20dp"
android:visibility="gone" />
</RelativeLayout>
fragment_rating_review.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.hybridelements.openchef.fragment_activities.fragment_subs.RatingFragment_Star">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/ratingReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/fragmentRating_reviewHeader"
android:textAlignment="center"
android:layout_marginTop="13dp"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/ratingStar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/ratingReview"
android:gravity="center_horizontal">
<EditText
android:id="#+id/userRateReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"/>
</RelativeLayout>
<Button
android:id="#+id/ratingBtnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ratingStar"
android:layout_alignParentEnd="true"
android:text="#string/ratingFrag_BtnSubmit"
style="#style/Widget.AppCompat.Button.Borderless"
android:enabled="false"/>
</RelativeLayout>
The RelativeLayout with id "ratingSection" in ratingSactivity_view_item.xml should follow the height of FrameLayout in fragment_rating_review.xml
This shouldn't happen.
This is before any typing (seems normal)
After typing, the submit button going off the screen
Try with this layout.
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/ratingReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="fragmentRating_reviewHeader"
android:textAlignment="center"
android:layout_marginTop="13dp"
android:textSize="16dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/ratingStar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ratingStar"
android:layout_below="#+id/ratingReview"
android:gravity="center_horizontal">
<EditText
android:id="#+id/userRateReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"/>
</RelativeLayout>
<Button
android:id="#+id/ratingBtnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_alignParentRight="true"
android:layout_below="#+id/ratingStar"
android:text="ratingFrag_BtnSubmit"
style="#style/Widget.AppCompat.Button.Borderless"
android:enabled="false"/>
</LinearLayout>
</FrameLayout>

How to place imageView inside AutocompleteTextView

I am trying to align the ImageView inside the Autocomplete textView. I did this but the ImageView appears below the AutocomplteTextView. I changed the width of textView but same problem arises. I am looking for something like this:
Is there any way I can achieve this?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kalpu.placepick.SearchFragment">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<AutoCompleteTextView
android:id="#+id/acTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="From"
android:dropDownHeight="match_parent"
android:hint="From"
android:visibility="visible"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/image"
android:padding="5dp"
android:layout_alignTop="#id/acTextView1"
android:layout_alignBottom="#id/acTextView1"
android:layout_alignRight="#id/acTextView1"
android:src="#mipmap/ic_arrow_drop_down"
/>
<AutoCompleteTextView
android:id="#+id/acTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/acTextView1"
android:completionHint="From"
android:dropDownHeight="match_parent"
android:hint="Intermediate (Optional) "
android:paddingTop="50dp"
android:visibility="visible" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/image"
android:padding="5dp"
android:layout_alignTop="#id/acTextView2"
android:layout_alignBottom="#id/acTextView2"
android:layout_alignRight="#id/acTextView1"
android:src="#mipmap/ic_arrow_drop_down"
/>
</LinearLayout>
</RelativeLayout>
Try below code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<AutoCompleteTextView
android:id="#+id/acTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="From"
android:dropDownHeight="match_parent"
android:hint="From"
android:padding="20dp"
android:visibility="visible"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/image"
android:layout_alignParentRight="true"
android:src="#mipmap/your_image"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="20dp">
<AutoCompleteTextView
android:id="#+id/acTextView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="From"
android:padding="20dp"
android:dropDownHeight="match_parent"
android:hint="Intermediate (Optional) "
android:visibility="visible" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#id/image"
android:src="#mipmap/your_image"
android:layout_alignParentRight="true"
/>
</RelativeLayout></LinearLayout>
Try this bro:
<FrameLayout
android:id="#+id/search"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
<android.support.v7.widget.AppCompatAutoCompleteTextView
android:id="#+id/autoCompleteSearch"
android:layout_width="260dp"
android:layout_height="40dp"
android:paddingLeft="10dp"
android:background="#android:color/transparent"
android:hint="Search by Event"
android:inputType="textAutoComplete"
android:textSize="14sp"
android:visibility="visible" />
<ImageView
android:id="#+id/searchBu"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical|right"
android:padding="10dp"
android:src="#mipmap/ic_arrow_drop_down" />
</FrameLayout>`
This is because you have placed the imageView below the AutoCompleteTextView in the xml. You will have to create a custom dropdown layout for images to appear in it.
You could check this library
https://github.com/koush/ion

RecyclerView adds marginBottom to its item

I have a RecyclerView that automatically adds a marginBottom to its childrens.
I already tried to put zero margins in XML and set 0 marginBottom programatically.
Android set these margins afeter onBindView of Adapter.
Its Like you can see in the image.
EDIT: Thats the 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="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/message_processo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#fff"
app:cardCornerRadius="5dp"
android:elevation="2dp"
android:orientation="vertical"
app:cardBackgroundColor="#color/white">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<br.com.isilist.android.view.widget.SquareImageView
android:id="#+id/iv_product_image"
android:src="#drawable/default_product_open_screen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"/>
<View
android:layout_below="#+id/iv_product_image"
android:layout_above="#+id/container_bottom"
android:id="#+id/middle_separator"
android:layout_width="match_parent"
android:layout_height="1px"/>
<RelativeLayout
android:layout_below="#+id/iv_product_image"
android:id="#+id/container_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:paddingLeft="5dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_name"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:textSize="16sp"
android:text="Teste"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#color/dark_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="4dp"
android:id="#+id/rl_sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/red_button">
<TextView
android:textSize="12sp"
android:textColor="#fff"
android:layout_margin="3dp"
android:text="#string/sale"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:id="#+id/tv_unit_price"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:textSize="13sp"
android:layout_marginBottom="#dimen/pad_5dp"
android:textColor="#888"
android:text="Teste"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/rl_bottom_layout_list_product">
<LinearLayout
android:id="#+id/ll_info_quantity_price"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_marginLeft="8dp"
android:layout_marginStart="#dimen/pad_8dp"
android:layout_marginRight="#dimen/pad_8dp"
android:layout_marginEnd="#dimen/pad_8dp"
android:background="#888"
android:layout_width="match_parent"
android:layout_height="1px"/>
<TextView
android:id="#+id/tv_item_quantity"
android:textSize="13sp"
android:textColor="#888"
android:text="Quantidade: 12"
android:layout_marginTop="#dimen/pad_4dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:textSize="13sp"
android:textColor="#color/primary_color"
android:text="R$"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_item_total_price"
android:textSize="#dimen/txt_18sp"
android:textColor="#color/primary_color"
android:text="148.99"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_marginBottom="-30dp"
android:layout_alignBottom="#+id/middle_separator"
android:id="#+id/ll_add_remove_item"
android:orientation="horizontal"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_toLeftOf="#+id/container_add_quantity"
android:layout_toStartOf="#+id/container_add_quantity"
android:elevation="3dp"
android:layout_margin="#dimen/pad_16dp"
android:id="#+id/container_deduct_quantity"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_minus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
<RelativeLayout
android:elevation="3dp"
android:layout_marginBottom="-30dp"
android:id="#+id/container_add_quantity"
android:layout_margin="#dimen/pad_16dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:background="#drawable/circle_background_orange_white_stroke"
android:layout_width="#dimen/pad_35dp"
android:layout_height="#dimen/pad_35dp">
<ImageView
android:src="#drawable/ic_plus_white_48dp"
android:layout_centerInParent="true"
android:layout_width="#dimen/pad_30dp"
android:layout_height="#dimen/pad_30dp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_badge"
android:layout_marginBottom="-12dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="#dimen/pad_16dp"
android:layout_alignBottom="#+id/middle_separator"
android:background="#drawable/circle_background_green"
android:layout_width="25dp"
android:layout_height="25dp">
<ImageView
android:id="#+id/iv_icon_badge_product"
android:src="#drawable/ic_check_white_48dp"
android:layout_centerInParent="true"
android:layout_width="20dp"
android:layout_height="20dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
There is a way to not allow RecyclerView to do that?
Two sources of this issue might be:
android:dividerHeight="" of your RecyclerView is too large. (In this case the last item doesn't have a bottom margin.)
Items themselves have their own bottom margin. (In this case all items have bottom margin.)

Categories

Resources