I have this weird problem that I have no idea where it's coming from.
I am making recipes app and I am using SQLite to display image, description and favorite check box. For recipe instructions I am not using SQLite , instead I am using TextView.
In my app I have two activities BreakfastActivity and Breakfast2Activity with their layouts that displays content which I mentioned above.The problem is that Breakfast Activity's XML code overwrites BreakfastActivity2 layout.
Note: The information that coming from database does't overwrite , but the one that comes from xml does.
I checked java activities if they use same layouts and if the layouts use the same context. Everything seems fine. I can't figure out where it can be potential problem.
Any Help would be appreciated.
This is activity_breakfast xml.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".BreakfastActivity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="#+id/photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textSize="20dp"
android:textColor="#454444"
android:textStyle="bold"/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="10dp"/>
<TextView
android:id="#+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="#+id/instructionsStepsCrepes1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep1"/>
<TextView
android:id="#+id/instructionsStepsCrepes2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep1"/>
<TextView
android:id="#+id/instructionsStepsCrepes3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsCrepesStep3"/>
<CheckBox
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/favorite"
android:layout_weight="2"
android:paddingLeft="10dp"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorPrimaryDark"
app:itemTextColor="#color/colorPrimaryDark"
app:menu="#menu/bottom_nav_menu">
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_navigation"
android:background="#drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
</LinearLayout>
</ScrollView>
This is BreakfastActivity.java
public class BreakfastActivity extends AppCompatActivity {
public static final String EXTRA_BREAKFASTID ="breakfastId";
private ShareActionProvider shareActionProvider;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast);
This is activity_breakfast2 xml
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".Breakfast2Activity">
//I added shadow to the toolbar using design library
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
//I referenced other layout (tool bar layout)
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_main" />
</android.support.design.widget.AppBarLayout>
<ImageView
android:id="#+id/photoBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:maxWidth="600dp"
android:maxHeight="300dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/nameBreakfast2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/descriptionBreakfast2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/instructionsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="Instructions"
android:paddingLeft="10dp"
android:textSize="20dp" />
<TextView
android:id="#+id/instructionsStepsOmellete1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep1"/>
<TextView
android:id="#+id/instructionsStepsOmellete2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep2"/>
<TextView
android:id="#+id/instructionsStepsOmellete3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="20dp"
android:paddingLeft="10dp"
android:text="#string/instructionsOmelleteStep3"/>
<CheckBox
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/favorite"
android:layout_weight="2"
android:onClick="onFavoriteClicked"/>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_gravity="bottom"
app:itemBackground="#color/colorPrimary"
app:itemIconTint="#color/colorPrimaryDark"
app:itemTextColor="#color/colorPrimaryDark"
app:menu="#menu/bottom_nav_menu" >
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_above="#id/bottom_navigation"
android:background="#drawable/shadow"/>
</android.support.design.widget.BottomNavigationView>
</android.support.design.widget.AppBarLayout>
this is ActivityBreakfast2.java
public class Breakfast2Activity extends AppCompatActivity {
public static final String EXTRA_BREAKFAST2ID = "BREAKFAST2Id";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast2);
Related
I have a problem with the focus. Everytime I click in the EditText I can write 1 character and then it loses the focus.
I´ve searched and I found some solutions if my EditText is inside a RecyclerView, but those don´t work with my project. I suspect that this is because my EditText is inside a RecyclerView which is inside a CustomDialog.
If someone know how to solve this it would be great :D
Edit:
This is the xml code of the CustomDialog that contains the RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:foregroundTint="#009688">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/nombreGasto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Nombre"
android:inputType="textPersonName"
android:minHeight="48dp" />
<EditText
android:id="#+id/precioGasto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Precio"
android:inputType="numberDecimal"
android:minHeight="48dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerGasto"
android:layout_width="match_parent"
android:layout_height="145dp" />
<Space
android:layout_width="match_parent"
android:layout_height="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#FFFFFF"
android:text="Cancel"
android:textColor="#00BCD4" />
<Button
android:id="#+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#FFFFFF"
android:text="OK"
android:textColor="#00BCD4" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
And this is the xml code of the CardView, which is the View that receives the RecyclerView, that contains the EditText:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/linearLay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/personNamePrecio"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="PersonaX"
android:textAlignment="viewStart"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="#+id/editTextPrecioPersona"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="0.00"
android:inputType="numberDecimal"
android:minHeight="48dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
We put requestFocus() and requestFocusFromTouch() and it works:
#personGasto is the editText
override fun afterTextChanged(p0: Editable?) {
#...
#some code
#...
personGasto.requestFocus()
personGasto.requestFocusFromTouch()
}
I have one fragment and I try to replace some another fragment in my layout.Here is a fragment replace code
public static void replace(FragmentManager fm, Fragment fragment, int container, String tag) {
FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(container, fragment, tag);
fragmentTransaction.commit();
}
Here is a main code
if (cardList != null && cardList.isEmpty()) {
hideDialog(pDialog);
drawavleView.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
norecordfragment = new NoRecordFragment();
norecordfragment.setAvatar(R.drawable.ic_card_nocard);
norecordfragment.setText(getActivity().getString(R.string.u_cards_no_data_text));
norecordfragment.setButtontext(getActivity().getString(R.string.u_cards_no_data_action));
norecordfragment.setAllowToShowAddAction(false);
floatingActionButton.setVisibility(View.VISIBLE);
FragmentUtils.replace(getActivity().getSupportFragmentManager(), norecordfragment,
R.id.upload_main_layout_upload,"norecordfragment");
}
Here is my xml code
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fitsSystemWindows="false">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:minHeight="#dimen/u_base_min_height">
<RelativeLayout
android:id="#+id/upload_main_layout_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay_v3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/upload_header_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/transfer_headerView_height"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#f2f2f2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/u_common_margin_left"
android:layout_marginRight="#dimen/u_common_margin_left"
android:layout_marginTop="#dimen/withdrow_change_card_height"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/u_widget_height"
android:background="#drawable/edittext_input_background_not_focus"
android:orientation="horizontal">
<EditText
android:id="#+id/u_major_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="7dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.65"
android:background="#null"
android:gravity="left"
android:hint="0.00"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
android:singleLine="true"
android:textColor="#4d4d4d"
android:textColorHint="#b2b2b2"
android:textSize="35dp" />
<Spinner
android:id="#+id/upload_spinner"
style="#style/Widget.MyApp.HeaderBar.Spinner"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/edittext_input_background_not_focus" />
<ImageView
android:id="#+id/u_open_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/transfer_user_description"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:padding="#dimen/slide_menu_hide_image"
android:src="#drawable/ic_menu_downarrow_grey" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lay_v4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:paddingLeft="#dimen/u_common_margin_left"
android:paddingRight="#dimen/u_common_margin_left">
<com.ripperLayout.MaterialRippleLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="#dimen/u_widget_height"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical"
app:mrl_rippleAlpha="0.2"
app:mrl_rippleColor="#ffffff"
app:mrl_rippleDelayClick="false"
app:mrl_rippleHover="true"
app:mrl_rippleOverlay="true"
app:mrl_rippleRoundedCorners="4dp">
<Button
android:id="#+id/u_done"
android:layout_width="fill_parent"
android:layout_height="#dimen/u_widget_height"
android:background="#drawable/rounded_corners_blue"
android:text="#string/u_register_next"
android:textColor="#ffffff"
android:textSize="#dimen/u_common_text_size_small" />
</com.ripperLayout.MaterialRippleLayout>
<View
android:layout_width="match_parent"
android:layout_height="#dimen/u_common_margin_left"
android:visibility="invisible" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/floating_action_bar_transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4D000000"
android:clickable="true"
android:orientation="vertical"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/floating_action_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_white"
app:backgroundTint="#48c9ff" />
</android.support.design.widget.CoordinatorLayout>
I don't know why in some devices I have this exception.
Exception java.lang.IllegalArgumentException: No view found for id 0x7f09052f (com.me.myapp:id/upload_main_layout_upload) for fragment NoRecordFragment{5309279 #4 id=0x7f09052f norecordfragment}
As you can see, I tried to replace my custom fragment inside upload_main_layout_upload layout, but I have this exception. What am I doing wrong? Thanks.
To implement a Fragment inside another layout, you need to have the layout that you are showing inside the Fragment in another fragment_layout.xml file. So you need to modify your current layout as follows.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:fitsSystemWindows="false">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:minHeight="#dimen/u_base_min_height">
<RelativeLayout
android:id="#+id/upload_main_layout_upload"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"/>
</ScrollView>
<LinearLayout
android:id="#+id/floating_action_bar_transparent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4D000000"
android:clickable="true"
android:orientation="vertical"
android:visibility="gone" />
<android.support.design.widget.FloatingActionButton xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/floating_action_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_add_white"
app:backgroundTint="#48c9ff" />
</android.support.design.widget.CoordinatorLayout>
And take the content inside the RelativeLayout outside of this layout and create another layout which will be used in your Fragment to get views from there.
Here's a sample fragment_layout.xml.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay_v3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/upload_header_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/transfer_headerView_height"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#f2f2f2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/u_common_margin_left"
android:layout_marginRight="#dimen/u_common_margin_left"
android:layout_marginTop="#dimen/withdrow_change_card_height"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/u_widget_height"
android:background="#drawable/edittext_input_background_not_focus"
android:orientation="horizontal">
<EditText
android:id="#+id/u_major_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="7dp"
android:layout_marginLeft="5dp"
android:layout_weight="0.65"
android:background="#null"
android:gravity="left"
android:hint="0.00"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
android:singleLine="true"
android:textColor="#4d4d4d"
android:textColorHint="#b2b2b2"
android:textSize="35dp" />
<Spinner
android:id="#+id/upload_spinner"
style="#style/Widget.MyApp.HeaderBar.Spinner"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/edittext_input_background_not_focus" />
<ImageView
android:id="#+id/u_open_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/transfer_user_description"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:padding="#dimen/slide_menu_hide_image"
android:src="#drawable/ic_menu_downarrow_grey" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You have too many nested layouts inside one as far as I can see. You need to rearrange your layouts as per your requirement and transaction flows between Activity and Fragments.
I have a ScrollView (with a RecyclerView inside) and a RelativeLayout after it which contains EditText. I added
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
for the activity in my manifest file because my keyboard overlaps the EditText but in effect, whenever the keyboard is active, the top part of my ScrollView is cut off.
I have tried using NestedScrollView and setting RelativeLayout android:layout_height="wrap_content" and android:layout_gravity="center" but that doesn't work. Below is the snippet of my code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView"
android:layout_alignParentTop="true"
android:background="#android:color/white"
android:scrollbars="vertical">
<RelativeLayout
...
</RelativeLayout>
<ScrollView
android:id="#+id/news_comments"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_title">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/individual_news_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:orientation="vertical">
// some other layouts
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/individual_news_item"
android:orientation="vertical"
android:paddingEnd="15dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingStart="15dp"
android:paddingTop="15dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/ll_message_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:id="#+id/ll_send_message"
android:layout_width="match_parent"
android:background="#android:color/white"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<github.ankushsachdeva.emojicon.EmojiconEditText
android:id="#+id/et_message_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/keyMessage"
android:inputType="textMultiLine|textNoSuggestions"
android:background="#android:color/transparent"
android:maxLines="4"
android:paddingBottom="5dp"
android:paddingEnd="0dp"
android:paddingLeft="20dp"
android:paddingRight="0dp"
android:paddingStart="20dp"
android:paddingTop="5dp"
android:textColor="#color/light_black"
android:textColorHint="#color/zipt"
android:textSize="17sp"
emojicon:emojiconSize="18sp" />
<ImageButton />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
any ideas how i can solve this?
I'm new to android development and i'm working on TabHost layout with three tabs so i made my xml file :
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ntm">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/Present"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Simple"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView24"
android:layout_weight="1"/>
<TextView
android:text="Continuous"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView23"
android:layout_weight="1"/>
<TextView
android:text="Perfect Simple"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView15"
android:layout_weight="1"/>
<TextView
android:text="Perfect Continuous"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView8"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/Past"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="NTM1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView25" />
</LinearLayout>
<LinearLayout
android:id="#+id/Future"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="NTM2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView26" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
and here is my code in the concerned activity to initialize the tabs :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
}
TabHost tab =(TabHost) findViewById(R.id.ntm);
tab.setup();
TabHost.TabSpec spec1 = tab.newTabSpec("PRESENT");
spec1.setIndicator("PRESENT");
spec1.setContent(R.id.Present);
tab.addTab(spec1);
TabHost.TabSpec spec2 = tab.newTabSpec("PAST");
spec2.setIndicator("PAST");
spec2.setContent(R.id.Past);
tab.addTab(spec2);
TabHost.TabSpec spec3 = tab.newTabSpec("FUTURE");
spec3.setIndicator("FUTURE");
spec3.setContent(R.id.Future);
tab.addTab(spec3);
I get this error:
cannot resolve symbol
On every methods like tab.setup() or all methods applicables on TabHost and TabSpec objects.
I've tried to copy/paste my code in the main activity and there I've got no errors but the application instantly crashes
I've found my mistake, i had not put the initializing code into the method onCreate i've got no more errors
I have tried to make a bottom sheet and it contains two rows , I want the first row only to be visible to the user when he opens the app .
When I ran the app on the emulator it was great but when i tried to run it on a real device (Samsung J7) the first row and a part of the second row appeared.
My question is how can I adjust my code so only 1 row appears on different screen sizes
Emulator Image
Real device screenshot
My xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:padding="0dp">
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dell.drawroutes.MapsActivity" />
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:background="#android:color/white"
android:clipToPadding="true">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="#dimen/card_margin"
android:columnCount="3">
<android.support.v7.widget.CardView
android:id="#+id/distancecard"
android:layout_width="wrap_content"
android:layout_height="#dimen/Card_View_Height"
android:layout_margin="#dimen/card_margin"
android:layout_columnSpan="1"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_columnWeight="1">
<LinearLayout
style="#style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Info"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World !" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="#dimen/Card_View_Height"
android:layout_marginBottom="#dimen/card_margin"
android:layout_marginLeft="#dimen/card_margin"
android:layout_marginRight="#dimen/card_margin"
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_column="1"
android:layout_row="0"
android:layout_columnWeight="1">
<LinearLayout
style="#style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Friends"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World !" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="#dimen/Card_View_Height"
android:layout_marginBottom="#dimen/card_margin"
android:layout_marginLeft="#dimen/card_margin"
android:layout_marginRight="#dimen/card_margin"
android:layout_columnSpan="1"
android:layout_column="2"
android:layout_gravity="fill"
android:layout_row="0"
android:layout_columnWeight="1">
<LinearLayout
style="#style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Related"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World !" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/durationcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/card_margin"
android:layout_marginLeft="#dimen/card_margin"
android:layout_marginRight="#dimen/card_margin"
android:layout_columnSpan="3"
android:layout_column="0"
android:layout_gravity="fill_horizontal"
android:layout_row="1">
<LinearLayout
style="#style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Duration"
android:textAppearance="#style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World !" />
</LinearLayout>
</android.support.v7.widget.CardView>
</GridLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps2);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
View bottomSheet = findViewById(R.id.bottom_sheet);
BottomSheetBehavior bottomSheetBehavior = bottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setPeekHeight(300);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
Your single card has a height (according to your layout):
#dimen/card_view_height
Pass this value to setPeekHeight function:
bottomSheetBehavior.setPeekHeight(getContext().getResources().getDimension(R.dimen.card_view_height));