last day (15 days later) » 

10:34
0
A: How to update edittext whenever a quantity is added in android studio

AorlinnYou should work with LiveData and DataBinding In order to do so you activate it in your build.gradle file: android { ... buildFeatures { dataBinding true } } Then add the following code. Add a ViewModel class: public class ViewModel extends AndroidViewModel { private fina...

You have added two layouts of same name ?
I guess second one is the fragment layout
private LiveData<Integer> mQuantity = new MutableLiveData<>(0); private LiveData<Integer> mOrderValue = new MutableLiveData<>(0); gives me 'MutableLiveData()' in 'android.arch.lifecycle.MutableLiveData' cannot be applied to '(int)'
And private FragmentBinding mBinding; giving me Cannot resolve symbol 'FragmentBinding'
Also when adding <data></data> it says cannot resolve class data
I am using <android.support.constraint.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" android:background="@drawable/background_round" android:padding="5sp"> in both fragment and product layout
When I am adding mViewModel = new ViewModelProvider(getActivity()).get(ViewModel.class); in my fragment class it giving me Cannot resolve constructor 'ViewModelProvider(android.app.Activity)'
There are lot of errors that need to be resolved :|
Can you please confirm me ?
Kindly check my Update 1
I changed the layouts. It's now just the important part. Btw. you sould not mix constraint and frame layout
I did understand but I am facing issues in my Fragment Class.
Did you go through the two links I added in the beginning of the post? You need to add some dependencies in your gradle.build file and some import statements in your class files..
I am going to check it, also I have added my whole class of Fragment you can also check it
10:34
The one I postet is for your product fragment or how you call it. And you are using regular inflator but you need to do it with the DataBindingUtil, otherwise you cannot set the variables.
Don't forget to set the viewmodel variable in your SurveyFormFragment (also use DataBindingUtil to infate it)
I have also added the error line in my question. Can you please check it?
And I have looked into the two links that you have provided me. But I can't find what to add more in my Gradle and in my external class.
10:45
I don't know why you cannot initialize mutablelivedata. Normally this should work but you can use setValue in the constructor of the class instead.
The FragmentBinding needs to be named with the name of your layout + binding. Lets say the layout is called product_layout.xml you need to use ProductLayoutBinding in the code.
So I can't use <data> with constraintlayout?
you can use data with every layout
<layout><data>... it's just like a wrapper around the layout you would use normally
Ok but when I do something like
<android.support.constraint.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"
android:background="@drawable/background_round"
android:padding="5sp">
<data>

<variable
name="viewmodel"
type="yourpackage.ViewModel" />
</data>
I am getting "Cannot resolve class data"
ah no it's not that way. you need to have <layout> on top and after the <data>..</data> section you add your constraint layout
<layout>
<data>
<variable ...>
</data>
<yourlayout like constraintlayout>...</yourlayout>
<layout>
got it
Ok I have done with the layouts but again I am stuck on my fragment class
as I have other elements also so I am having difficulty doing it
I am using ` mViewModel = new ViewModelProvider(getActivity()).get(ViewModel.class);`
but getting error
Cannot resolve constructor 'ViewModelProvider(android.app.Activity)'
Also I have initialized it like below
newSurveyFormLayoutBinding = DataBindingUtil.setContentView(getActivity(),R.layout.new_survey_form_layout);
but when I want to do newSurveyFormLayoutBinding.quantity or newSurveyFormLayoutBinding.order_value I can't find quantity and order_value
here is my fargment layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>

<variable
name="viewmodel"
type="com.example.thumbsol.accuratesurvey.models.ViewModel" />
</data>

<android.support.design.widget.CoordinatorLayout 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:background="@color/white"
android:orientation="vertical"
my product layout
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>

<variable
name="quantity"
type="android.arch.lifecycle.MutableLiveData&lt;Integer&gt;" />

<variable
name="order_value"
type="android.arch.lifecycle.MutableLiveData&lt;Integer&gt;" />
</data>
<android.support.constraint.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"
11:31
did you recompile? The variables are only updated after compilation. When you use intellisense what do you see?
what versions are you working with? because you see to not have a lot of constructor parameters available that should be there...
yes I am recompling it now
 
2 hours later…
13:23
Did it work?

last day (15 days later) »