I am getting problem in data binding. In the application, the default value of TextView is not showing. TextView is just blank.
XML File
<TextView
android:id="#+id/tvDoctorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text='#{doctorsInfo.name , default="FetchingData"}'
android:textAppearance="#style/SuperHeadingText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Use this:
android:text='#{doctorsInfo.name, default="FetchingData"}'
OR
android:text="#{doctorsInfo.name, default=`FetchingData`}"
Instead of:
android:text='#{doctorsInfo.name , default="FetchingData"}'
Use this
android:text='#{doctorsInfo.name, default="FetchingData"}'
Related
I have a ConstraintLayout that is a list item inside of a GridView, so there will be multiple of them on the screen. There are various statuses for each item, which are represented by drawables, and each list item has a unique name in a TextView displayed above the drawable.
Basically I have these two inside a Constraint Layout:
<ImageView
android:id="#+id/client_state_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:src="#drawable/client_state_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/device_client"
style="#style/ClientName"
android:layout_width="64dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="72dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Where client_state_background can be one of multiple drawables, determined programmatically.
I'm trying to run an espresso test that will ensure that the correct list item is showing the drawable for the status. I tried doing this:
ViewInteraction imageView = onView(allOf(withId(R.id.client_state_image), withParent(withParent(withId(R.id.grid_view))), withDrawable(statusToCheck), isDisplayed()));
imageView.check(matches(isDisplayed()));
With the withDrawable method drawn from here
But I can't find a way to include the TextView in my assertion.
Is there a way to assert that a TextView and ImageView are displaying the correct information, together?
Let me try to explain the title.
I have a manufacturer TextView that is populated from MYSQL. When a manufacturer is selected it populates the Model TextView.
Now I want to add OTHER in each model, and when it is selected an EditText appears. Something like this:
-FORD
---Mustang
---Escape
---Other
-BMW
---X5
---Z4
---Other
Now whenever Other is selected, the EditText appears. If not, then it remains hidden.
The only way I got it working is by creating a field in mysql for each model. I am hoping there is a better approach.
Here is what I have done.
enter code here
<EditText
android:id="#+id/fordTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="#dimen/space_12"
android:hint="#string/item_entry__model"
android:paddingLeft="#dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="#dimen/space_12"
android:paddingRight="#dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="#color/text__primary"
android:textSize="14sp"
app:font='#{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/plateNumTextView" />
<EditText
android:id="#+id/bmwTextView"
android:layout_width="0dp"
android:layout_height="130px"
android:layout_marginStart="16dp"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:background="#drawable/custom_progress_bar_horizontal"
android:inputType="textPersonName"
android:paddingStart="#dimen/space_12"
android:hint="#string/item_entry__model"
android:paddingLeft="#dimen/space_12"
android:paddingTop="8dp"
android:paddingEnd="#dimen/space_12"
android:paddingRight="#dimen/space_12"
android:paddingBottom="8dp"
android:textAlignment="viewStart"
android:textColor="#color/text__primary"
android:textSize="14sp"
app:font='#{"normal"}'
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/fordTextView" />
Here is is the java
if (itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.VISIBLE);
binding.get().bmwTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_FORD_OTHER)){
binding.get().fordTextView.setVisibility(View.GONE);
binding.get().fordTextView.setText("");
}
if (itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.VISIBLE);
binding.get().fordTextView.setVisibility(View.GONE);
}
if (!itemViewModel.holder.model_id.equals(Constants.MODEL_BMW_OTHER)){
binding.get().bmwTextView.setVisibility(View.GONE);
binding.get().bmwTextView.setText("");
}
Is there a way of doing this by using only one EditText?
You can achieve this using single EditText, when ever click is registered for particular model Other button, set the model_id of that model as tag to the EditText. And while reading input from EditText, always check for tag to get the model_id
binding.get().modelTextView.setTag(""+itemViewModel.holder.model_id);
I know there are many similar questions, and I have read many answers, but none of them are what I want. I have tried almost all of them. The following are my attempts (I set ellipsize=end for each attempt):
singleLine=true (works)
lines=1 (not work)
maxLines=1 (not work)
set width of textView to specific value (not work)
ScrollHorizontally=true (not work)
Only the first one works, but I want multiple lines of text instead of one line
Is there any other way to achieve this
Any help will be appreciated
Edit:
And here is my xml layout(in attempt 2):
<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">
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="#dimen/x150"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:lines="1"
android:text="hello hello hello hello hello hello hello hello hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image" />
</androidx.constraintlayout.widget.ConstraintLayout>
I used ellipsize=true in the project I developed before, and it worked well in that project, I compared the code of the current project with the previous one. There is no difference between each other, so I am confused with the current project, so I pulled the previous project from github and ran it, and found that it NOT WORK in my xml renderer, but it WORKS on my phone.
Eventually I found it is the problem of the renderer. I found the button to upgrade the renderer. Now I use the latest renderer, and it also works fine in the redener now.
This is working fine for me
<TextView
android:id="#+id/textView8"
android:layout_width="0dp"
app:layout_constraintEnd_toEndOf="parent"
android:ellipsize="end"
android:lines="3"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="TextVie mbdfdsvffmnsvfbnsddfdfvfndvfnbdvfbndsvfnsdvfnsdvfnsdvfnsbfjnbdsvjfvdsjhfvsdjhvsdsdvfjdvfjsdvfjhsdvfjsdvfjdhsvfhjdvfjdvfhjdvfjdsvfjsvfhjsdvfjsdvfjsdvfjsdvfjsdvfnsdfvbnsdvfbnsdvfnsdvfnsdbvfnbsdvnsdvsdvbfsdnbfw"
android:textSize="16dp" />
try adding maxLines with the lines count you want
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:ellipsize="end"
android:maxLines="4"
android:text="hello\n hello\n hello\n hello hello hello hello hello hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image" />
Please note that the ellipsis will only be shown if the text size exceeds the number of lines allowed or the text size width; otherwise, it will not be shown.
If what you want is that at the end of the text the ellipsis is always shown, you must create a method which concatenates the (text + "...").
something like this:
TextView textView = findViewById(R.id.textView);
String valueText = textView.getText().toString();
if (!valueText.isEmpty()) valueText = String.format("%s...", valueText);
textView.setText(valueText);
The following example shows the ellipsis mentioned above, the first text exceeds the size of the text view and the second does not.
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="hello hello hello hello hello hdsafsfdfdel sdsdasdsadasdsadsadasdasdsadsaadssadsadsadsadsasadsadsadsadsadsadsaadsalo hello hello hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"
android:textColor="#android:color/black"
android:textSize="16sp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:ellipsize="end"
android:maxLines="2"
android:text="hello hello hello hello hello hel sfdsafsafsfasfsafsafsahhhhhhhhhhhhhh"
android:textColor="#android:color/black"
android:textSize="16sp"
app:layout_constrainedWidth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
Set property in java file
yourTextView.setEllipsize(TextUtils.TruncateAt.END);
yourTextView.setMaxLines(3);
yourTextView.setText("long text");
I'm using two-way databinding.
I have some data inside my Room databse and depending on what user writes in edittext showing that value in textview.
When I rotate screen, value gets updated. At fist its empty string then back to how it was. I know this is normal behavior of activity lifecycle.
So I would like to know the best way to get rid of this problem.
Thanks in advance.
EditText:
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/edtOddelek"
android:text="#={viewModel.loginOddelek}"
android:layout_marginEnd="8dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/textView3"
app:layout_constraintBottom_toBottomOf="#+id/textView3"
app:layout_constraintStart_toStartOf="#+id/edtGeslo" style="#style/adoEditTextStyle"/>
TextView:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/txtOddelek"
android:layout_marginTop="8dp"
android:text="#{viewModel.oddelek}"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="12dp"
android:textColor="#color/orangeDark"
app:layout_constraintTop_toBottomOf="#+id/edtOddelek"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="12dp"/>
ViewModel:
val loginOddelek = NonNullMutableLiveData<String>("")
val oddelek:LiveData<String> = Transformations.switchMap(loginOddelek){
settingsModel.getSifrPr(it)
}
First of all, take a look at this screeshot:
I want to place a close button in this modal like this:
But I can't figure out how to do that, here is going my layout file:
<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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="br.com.makadu.makaduevento.ui.fragments.wizardInteligenceArtificial.WizardAIFifthStep">
<android.support.constraint.ConstraintLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv_title_subjects_schedule_suggestion"
android:paddingTop="#dimen/screen_title_top_bot_padding"
android:paddingBottom="#dimen/screen_title_top_bot_padding"
android:background="#color/Verde2"
android:gravity="center_horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="#dimen/txt_medium"
android:text="#string/str_screen_title_subjects"
tools:layout_constraintTop_creator="1"
tools:layout_constraintRight_creator="1"
app:layout_constraintRight_toRightOf="parent"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:text="#string/str_according_to_your_interests_title"
style="#style/Theme.DefaultTextView.PrimaryDark.Bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
android:id="#+id/tv_according_interests"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/tv_title_subjects_schedule_suggestion" />
<ExpandableListView
android:id="#+id/elv_suggested_schedule"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/tv_according_interests"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/b_confirm_schedule">
</ExpandableListView>
<Button
android:id="#+id/b_confirm_schedule"
style="#style/Theme.DefaultButton.Purple.Radius"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/str_confirm_schedule_button"
tools:layout_constraintLeft_creator="1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
Thanks in advance.
Well stackoverflow is asking me to explain better my problem, but i guess the pictures explain it selfs, so I'm now just writing any no sense text.
The first solution, it will work 100% but I think not beautiful:
You can make root layout transparent and put in it needed visible views. U can set OnClickListener for root view to hide dialog on tap out visible views.
The second solution, maybe it will work I can't check now:
You can turn off clipPadding for root view and move yo close button out of visible.
P.S. I wrote from phone so it has not good view format and without samples.
I runed on similar issue, u should Create a LinearLayout With a gravity center and margin with background transparent, the add a RelativeLayout with the content of your dialog.
In the RelativeLayout u can use the android:layout_alignParentRight="true" & android:layout_alignParentTop="true" for the ImageView containing the close button (probably u will need to use some margins too) so it will be displayed above the textview containing the title of your dialog.
I hope this helped you, tomorrow i will try to send u a code for this !