I have some checkboxs that don't work correctly. Checkboxs result checked but there are no check marks. If click on checkbox twice, check mark appears.
On the emulator there are no problem, but on my Galaxy S7 (Oreo) there is this bug. Checkboxs are checked programmaticaly after loading data from db:
#Override
protected void onPostExecute(Boolean successo) {
pbGestioneProfilo.setVisibility(View.GONE);
if (successo) {
passioniET.setText(passioni);
libriET.setText(libri);
filmserieET.setText(filmserie);
negoziET.setText(negozi);
tecnologiaCB.setChecked(tecnologia.equals(Utils.TRUE) ? true : false);
sportCB.setChecked(sport.equals(Utils.TRUE) ? true : false);
viaggiCB.setChecked(viaggi.equals(Utils.TRUE) ? true : false);
casacucinaCB.setChecked(casacucina.equals(Utils.TRUE) ? true : false);
abbigliamentoCB.setChecked(abbigliamento.equals(Utils.TRUE) ? true : false);
if (!urlProfilo.equals("")) {
Glide.with(getContext())
.load(urlProfilo)
.into(imgprofilo);
}
} else {
Log.d("MYTAG","ERROR");
Toast.makeText(getContext(),"Error",Toast.LENGTH_SHORT).show();
}
}
On xml:
<ScrollView
android:background="#drawable/backgroundtab"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
<CheckBox
android:id="#+id/tecnologiaCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:text="Tecnologia"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/interessiTV" />
<CheckBox
android:id="#+id/sportCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Sport"
app:layout_constraintBaseline_toBaselineOf="#+id/tecnologiaCB"
app:layout_constraintStart_toEndOf="#+id/tecnologiaCB" />
<CheckBox
android:id="#+id/viaggiCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:text="Viaggi"
app:layout_constraintBaseline_toBaselineOf="#+id/tecnologiaCB"
app:layout_constraintStart_toEndOf="#+id/sportCB" />
<CheckBox
android:id="#+id/casacucinaCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Casa e Cucina"
app:layout_constraintStart_toStartOf="#+id/tecnologiaCB"
app:layout_constraintTop_toBottomOf="#+id/tecnologiaCB" />
<CheckBox
android:id="#+id/abbigliamentoCB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Abbigliamento"
app:layout_constraintBaseline_toBaselineOf="#+id/casacucinaCB"
app:layout_constraintStart_toStartOf="#+id/sportCB" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Is it possibile to fix?
Thank you
Related
Kindly let me know How we can create radio button with image and selected true button?
Here I have attached the screen shot that what i need?
I made three custom radio button using textview you can use imageview
this is my xml
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:id="#+id/tv_home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:text="#string/home"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
app:drawableTopCompat="#drawable/ic_home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/tv_jpg"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/tv_jpg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:text="#string/files"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
app:drawableTopCompat="#drawable/ic_files"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/tv_pdf"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/tv_home" />
<TextView
android:id="#+id/tv_pdf"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
android:text="#string/pdf"
app:drawableTopCompat="#drawable/ic_pdf"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/tv_jpg" />
</androidx.constraintlayout.widget.ConstraintLayout>
in onCreate of activity write this code
tv_home.setOnClickListener {
setSelected(tv_home)
}
tv_jpg.setOnClickListener {
setSelected(tv_jpg)
}
tv_pdf.setOnClickListener {
setSelected(tv_pdf)
}
and outer side of oncreate make a method as
private fun setSelected(pTextViw: TextView) {
if (tv_home == pTextViw) {
tv_home.compoundDrawables[1].setTint(mSelectedColor)
tv_home.setTextColor(mSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mUnSelectedColor)
tv_jpg.setTextColor(mUnSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mUnSelectedColor)
tv_pdf.setTextColor(mUnSelectedColor)
} else if (tv_jpg == pTextViw) {
tv_home.compoundDrawables[1].setTint(mUnSelectedColor)
tv_home.setTextColor(mUnSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mSelectedColor)
tv_jpg.setTextColor(mSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mUnSelectedColor)
tv_pdf.setTextColor(mUnSelectedColor)
} else if (tv_pdf == pTextViw) {
tv_home.compoundDrawables[1].setTint(mUnSelectedColor)
tv_home.setTextColor(mUnSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mUnSelectedColor)
tv_jpg.setTextColor(mUnSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mSelectedColor)
tv_pdf.setTextColor(mSelectedColor)
}
}
I was updating an existing code by introducing dismiss button, and the onClick Butterknife method is not working for dismiss button, whereas its working for close button. In the below code, I am enabling the close button for some devices and for other devices I am enabling the dismiss button. I am quite unsure why this "dismiss" button is not working, whereas the close button is working fine. And both of them use the ButterKnife, onClick method - onSkip()
InfoActivity.java :
public class InfoActivity extends BccActiviy {
#BindView(R.id.ImageView_CloseView)
ImageView tCloseView;
#BindView(R.id.Dismiss)
Button tDismiss;
.....
#OnClick({R.id.Dismiss, R.id.ImageView_CloseView})
public void onSkip(View v) {
onDissmissPressed();
}
public void initialize(Bundle savedInstanceState) {
if (tConfig.isDismiss()) {
tCloseView.setVisibility(View.GONE);
tDismiss.setVisibility(View.VISIBLE);
} else {
tDismiss.setVisibility(View.GONE);
}
}
}
info_screen.xml :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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"
tools:ignore="All"
android:id="#+id/root_layout"
android:background="#color/fd_theme"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ImageView_CloseView"
style="#style/CancelButton"
android:layout_width="#di/target_size"
android:layout_marginTop="#di/p_6"
android:layout_height="#di/target_size"
android:layout_alignParentStart="true"
android:clickable="true"
android:contentDescription="#string/close_btn_txt"
android:importantForAccessibility="yes"
android:paddingStart="#di/p_14"
android:paddingEnd="#di/p_14"
android:background="?attr/bg_color"
app:srcCompat="#drawable/icn_close_white"/>
<LinearLayout
android:id="#+id/TextView_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/TextContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="#di/size_2x"
android:focusableInTouchMode="true"
android:gravity="center"
android:text="#string/text"
android:textColor="#color/white"
android:textSize="#di/rating"
android:textAlignment="center"/>
<com.package.button.star.views.widgets.StaView
android:id="#+id/StarView_AppRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
</com.package.button.star.views.widgets.StarView>
<Button
android:id="#+id/Dismiss"
style="#style/buttonStyle"
android:layout_marginTop="#di/margin_top"
android:paddingLeft="#di/padding_50"
android:paddingTop="#di/padding_18"
android:paddingRight="#di/padding_50"
android:paddingBottom="#di/padding_18"
android:text="Dismiss"
android:onClick="onSkip"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="#di/dismiss_fontSize"
android:visibility="visible"
android:focusable="true"
tools:text="Dismiss" />
<ViewStub
android:id="#+id/actions_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#di/margin_center"
android:inflatedId="#+id/view_actions"
android:layout="#layout/view_actions" />
</LinearLayout>
</FrameLayout>
Try removing the onClick from xml.
I am facing a problem with the position of the error indicator of my EditText when calling editText.setError("...").
As you can see in the screenshot I am using a BottomSheetDialog with an EditText inside of it. When I display the error indicator, the text is completely out of place. It seems as if the dialog "thinks" that it is full-screen, while it is actually not.
This is my dialog layout file (phone_dialog.xml):
<android.support.constraint.ConstraintLayout 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="wrap_content"
android:layout_weight="0"
android:orientation="vertical">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:padding="#dimen/padding_layout_normal"
android:text="#string/dialog_title_edit_phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:id="#+id/etPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:inputType="phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvTitle"/>
<Button
android:id="#+id/btnSavePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etPhone"/>
</android.support.constraint.ConstraintLayout>
My Activity layout file (activity_contacts.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"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvContacts"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
This is how I show the dialog from my Activity:
PhoneBottomDialog dialog = new PhoneBottomDialog(Context);
dialog.show();
This is my PhoneBottomDialog class:
public class PhoneBottomDialog extends BottomSheetDialog {
public PhoneBottomDialog(Context context) {
super(context);
View view = getLayoutInflater().inflate(R.layout.phone_dialog, null);
setContentView(view);
// additional setup below this...
}
// ...
}
I am not performing any other layouting inside my custom PhoneButtomDialog. Changing the root layout of my dialog to RelativeLayout or LinearLayout as well as adding a ScrollView did not change anything. It's also not a device or specific Android version related issue as the problem occurs on all of my testing devices ranging from Android 5.0 to 7.1, it also occurs on the emulator.
Does anyone have an idea why this is happening?
You can use TextInputLayout and inside that you can define Edit Text.
I have done some modification inside your phone_dialog.xml.
phone_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="bottom"
android:background="#android:color/holo_blue_light"
android:padding="10dp"
app:behavior_hideable="true"
app:behavior_peekHeight="60dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:gravity="center"
android:padding="10dp"
android:text="dialog_title_edit_phone" />
<android.support.design.widget.TextInputLayout
android:id="#+id/inputPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/TextInputLayoutLabel">
<EditText
android:id="#+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone"
android:imeOptions="actionDone"
android:inputType="phone"
android:maxLines="1"
android:textSize="20sp" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/btnSavePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/etPhone"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="8dp"
android:text="Save" />
</LinearLayout>
</FrameLayout>
Inside style.xml add this.
<style name="TextInputLayoutLabel" parent="Widget.Design.TextInputLayout">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#android:color/black</item>
<item name="android:textSize">15sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorControlNormal">#color/colorAccent</item>
<item name="colorControlActivated">#color/colorAccent</item>
</style>
PhoneBottomDialog.java
public class PhoneBottomDialog extends BottomSheetDialog {
TextInputLayout inputPhone;
EditText edtPhone;
Button btnSave;
public PhoneBottomDialog(Context context) {
super(context);
View view = getLayoutInflater().inflate(R.layout.phone_dialog, null);
setContentView(view);
// additional setup below this...
inputPhone = (TextInputLayout) view.findViewById(R.id.inputPhone);
edtPhone = (EditText) view.findViewById(R.id.etPhone);
btnSave = (Button) view.findViewById(R.id.btnSavePhone);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!validatePhone())
return;
}
});
}
private boolean validatePhone() {
if (edtPhone.getText().toString().isEmpty()) {
inputPhone.setError("Please enter valid phone number with country code.");
requestFocus(edtPhone);
return false;
} else {
inputPhone.setErrorEnabled(false);
}
return true;
}
private void requestFocus(View view) {
if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
// ...
}
And inside Activity.
#SuppressLint("SetTextI18n")
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test24);
mContext = this;
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
PhoneBottomDialog dialog = new PhoneBottomDialog(mContext);
dialog.show();
}
Below you can see the output for this.
add compile 'com.android.support:design:24.2.0' in gradle dependencies
use TextInputLayout in xml.
<android.support.design.widget.TextInputLayout
android:id="#+id/textInputServer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="36dp"
app:errorTextAppearance="#style/TextErrorAppearance">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
........./>
</android.support.design.widget.TextInputLayout>
From Lollipop(5.0) version android provide TextInputLayout to do this.
Use below xml and java code to show same type view.
abc.xml:
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input_layout_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
app:theme="#style/AppTheme">
<android.support.v7.widget.AppCompatEditText
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:imeOptions="actionNext"
android:inputType="text"
android:singleLine="true"
android:textColor="#color/icons"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
Abc.java:
private TextInputLayout
textInputLayout_User = (TextInputLayout) findViewById(R.id.text_input_layout_user);
textInputLayout_User.setError(getString(R.string.valid_username));
I am currently experiencing a weird issue with MvvmCross on android. I want to data bind a a view to a ViewModel. My setup is as follows
public class ForumTopicItemsViewModel : MvxViewModel
{
ObservableCollection<ForumReplyListModel> _forumComments;
ForumTopicDetailsModel _topic;
long _forumId;
long _topicId;
bool _busy;
int _page;
public ForumTopicItemsViewModel()
{
_topic = new ForumTopicDetailsModel()
{
DateCreated = DateTime.Now.AddDays(-1),
Discussion = "Just the fact that I dont care about what is displayed here",
ForumId = ForumId,
TopicId = TopicId,
Topic = "Another Heading, Just for the sake of it"
};
_forumComments = new ObservableCollection<ForumReplyListModel>
{
new ForumReplyListModel()
{
CreatedBy = "Peter Edike",
DateCreated = DateTime.Now.AddDays(-1),
Reply = "Just a reply to show how far I have come"
}
};
}
public int Page
{
get { return _page; }
set { SetProperty(ref _page, value); }
}
private static bool IsHostReachable()
{
var nReachability = Mvx.Resolve<IMvxReachability>();
return nReachability.IsHostReachable(AppConfiguration.RequestUrl);
}
public ObservableCollection<ForumReplyListModel> Comments
{
get { return _forumComments; }
set { SetProperty(ref _forumComments, value); }
}
public ForumTopicDetailsModel Topic
{
get { return _topic; }
set { SetProperty(ref _topic, value); }
}
public string Heading => this.Topic.Topic;
public string Description => this.Topic.Discussion;
public string DateCreatedString => this.Topic.DateCreatedString;
public bool Busy
{
get { return _busy; }
set { SetProperty(ref _busy, value); }
}
public long ForumId
{
get { return _forumId; }
set {SetProperty(ref _forumId, value); }
}
public long TopicId
{
get { return _topicId; }
set { SetProperty(ref _topicId, value); }
}
public void Init(long TopicId, long ForumId)
{
this.TopicId = TopicId;
this.ForumId = ForumId;
}
}
and I have the Android XML View Like So
<?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">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxBind="Refreshing Busy; RefreshCommand LoadReplyCommand">
<MvxRecyclerView
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxItemTemplate="#layout/listitem_commentlist"
app:MvxBind="ItemsSource Comments;" />
</MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout>
<View
android:layout_width="match_parent"
android:layout_height="4px"
android:background="#color/grey_soft" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="#dimen/spacing_medium"
app:cardElevation="#dimen/spacing_xsmall"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_medium"
android:layout_marginLeft="#dimen/spacing_large"
android:layout_marginRight="#dimen/spacing_large"
android:layout_marginTop="#dimen/spacing_large"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textColor="#color/upload_photo_button_color"
app:MvxBind="Text Heading" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:text="#string/lorem_ipsum"
app:MvxBind="Text Description"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/grey_dark" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/grey_soft" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
app:MvxBind="Text DateCreatedString"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/upload_photo_button_color"
android:textStyle="italic" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Problem:
The contents of the MvxRecyclerView are never displayed even though i made sure that the collection had items in the constructor.
Every other binding works as expected. If I however comment out everything except the MvxRecyclerView, it becomes visible.
Please I think I did something wrong.
Can someone point me in the right direction?
Thank You.
None of your LinearLayout's seem to have an orientation set. I think the default one is set to Horizontal meaning your layout flows from left to right and go outside of the visible area of your screen.
Also another problem is that your layout is awfully nested, meaning it will probably have a significant amount of overdraw and extra measurement passes when it is going to be drawn on the screen. You can un-nest it by using a single RelativeLayout instead of the 4 nested layers of LinearLayout.
Something like this might work:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout
android:layout_alignParentTop="true"
android:layout_above="#+id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:MvxBind="Refreshing Busy; RefreshCommand LoadReplyCommand">
<MvxRecyclerView
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:MvxItemTemplate="#layout/listitem_commentlist"
app:MvxBind="ItemsSource Comments" />
</MvvmCross.Droid.Support.V4.MvxSwipeRefreshLayout>
<View
android:id="#+id/divider"
android:layout_above="#+id/heading_card"
android:layout_width="match_parent"
android:layout_height="4px"
android:background="#color/grey_soft" />
<android.support.v7.widget.CardView
android:id="#+id/heading_card"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="#dimen/spacing_medium"
app:cardElevation="#dimen/spacing_xsmall"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/spacing_medium"
android:layout_marginLeft="#dimen/spacing_large"
android:layout_marginRight="#dimen/spacing_large"
android:layout_marginTop="#dimen/spacing_large"
android:textAppearance="#style/TextAppearance.AppCompat.Headline"
android:textColor="#color/upload_photo_button_color"
app:MvxBind="Text Heading" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
android:text="#string/lorem_ipsum"
app:MvxBind="Text Description"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/grey_dark" />
<View
android:layout_width="match_parent"
android:layout_height="2px"
android:background="#color/grey_soft" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/spacing_large"
app:MvxBind="Text DateCreatedString"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="#color/upload_photo_button_color"
android:textStyle="italic" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
I have a FragmentActivity with this layout:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/menulabel"
android:textSize="24sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:layout_below="#+id/textView1"
android:hint="#string/search_title_hint" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/spinnersearch"
android:layout_below="#+id/editText1" />
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2" >
<Spinner
android:id="#+id/spinner_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:prompt="#string/spinnersearch" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/reset_search" />
</LinearLayout>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttonnewcat"
android:layout_below="#+id/layout1" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttondelcat"
android:layout_below="#+id/button2" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttoneditcat"
android:layout_below="#+id/button3" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttonnewtext"
android:layout_below="#+id/button4" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttondeltext"
android:layout_below="#+id/button5" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<side.menu.scroll.ScrollerLinearLayout
android:id="#+id/menu_content_side_slide_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#drawable/ab_solid_example"
android:orientation="horizontal" >
<ImageView
android:id="#+id/main_tmp_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/actionbar_background"
android:src="#drawable/download" />
</LinearLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_groud" />
</side.menu.scroll.ScrollerLinearLayout>
</RelativeLayout>
and the ScrollerLinearLayout class is something like this:
public class ScrollerLinearLayout extends LinearLayout {
// code of the class
}
How to access from ScrollerLinearLayout to the parent layout to get - for example - the editetxt? FragmentActivity and ScrollerLineraLayout are in different packages of the same projects.
I tried to use the getParent() function in this way within the ScrollerLinearLayout but it doesn't work.
RelativeLayout r = (RelativeLayout) this.getParent().getParent();
int w = r.findViewById(R.id.editText1).getLayoutParams().width;
Someone help me? Thanks!
The getParent method returns a ViewParent, not a View. You need to cast the first call to getParent() also:
RelativeLayout r = (RelativeLayout) ((ViewGroup) this.getParent()).getParent();
As stated in the comments by the OP, this is causing a NPE. To debug, split this up into multiple parts:
ViewParent parent = this.getParent();
RelativeLayout r;
if (parent == null) {
Log.d("TEST", "this.getParent() is null");
}
else {
if (parent instanceof ViewGroup) {
ViewParent grandparent = ((ViewGroup) parent).getParent();
if (grandparent == null) {
Log.d("TEST", "((ViewGroup) this.getParent()).getParent() is null");
}
else {
if (parent instanceof RelativeLayout) {
r = (RelativeLayout) grandparent;
}
else {
Log.d("TEST", "((ViewGroup) this.getParent()).getParent() is not a RelativeLayout");
}
}
}
else {
Log.d("TEST", "this.getParent() is not a ViewGroup");
}
}
//now r is set to the desired RelativeLayout.
If you are trying to find a View from your Fragment then try doing it like this:
int w = ((EditText)getActivity().findViewById(R.id.editText1)).getLayoutParams().width;
You can get ANY view by using the code below
view.rootView.findViewById(R.id.*name_of_the_view*)
EDIT: This works on Kotlin. In Java, you may need to do something like this=
this.getCurrentFocus().getRootView().findViewById(R.id.*name_of_the_view*);
I learned getCurrentFocus() function from: #JFreeman 's answer
The RelativeLayout (i.e. the ViewParent) should have a resource Id defined in the layout file (for example, android:id=#+id/myParentViewId). If you don't do that, the call to getId will return null. Look at this answer for more info.
Check my answer here
The use of Layout Inspector tool can be very convenient when you have a complex view or you are using a third party library where you can't add an id to a view
parent as View
fun View.printParentSize() {
log("parentWidth = ${(parent as View).sizeW}")
log("parentHeight = ${(parent as View).sizeH}")
}
This also works:
this.getCurrentFocus()
It gets the view so I can use it.