Null editexts in databinding activity
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
How to set data in editexts with databinding from Viewmodel?
I'm passing parameters from the RecyclerView Item to the ViewModel in OnItemClick and in logs everything looks fine, but the Edittexts are still empty. when I tried to set the String created in ViewModel and was the same. EditTexts are still empty. I no have idea where is error.
ViewModel:
public class MainViewModel extends AndroidViewModel implements RecyclerViewAdapter.OnItemClickListener {
private TaskRepository taskRepository;
private LiveData<List<Task>> allTasks;
public ObservableField<String> description = new ObservableField<>();
public ObservableField<String> date = new ObservableField<>();
public ObservableField<String> time = new ObservableField<>();
String TAG;
public MainViewModel(@NonNull Application application) {
super(application);
taskRepository = new TaskRepository(application);
allTasks = taskRepository.getAllTasks();
}
public LiveData<List<Task>> getAllTasks() {
return allTasks;
}
public void deleteTask(Task task) {
taskRepository.delete(task);
}
@Override
public void onItemClick(View view, Task item) {
Log.d(TAG, "MVM " + view + " / " + item.getDescription() + " / " + item.getDate() + " / " + item.getTime());
description.set(item.getDescription());
date.set(item.getDate());
time.set(item.getTime());
}
XML file:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="editTaskViewModel"
type="com.example.daniellachacz.taskmvvm.viewmodel.MainViewModel">
</variable>
<variable
name="editTaskInterface"
type="com.example.daniellachacz.taskmvvm.view.OnEditTaskClickInterface">
</variable>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/title"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:clickable="false"
android:focusable="false"
android:text="Edit task"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="25sp" />
<EditText
android:id="@+id/edit_description_text"
android:layout_width="320dp"
android:layout_height="40dp"
android:layout_below="@+id/title"
android:layout_alignStart="@+id/title"
android:backgroundTint="#FFF"
android:text="@={editTaskViewModel.description}"
android:textColor="#FFF"
android:textColorHint="#949393"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/edit_date_text"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/edit_time_text"
android:layout_marginStart="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select date"
android:onClick="@{()-> editTaskInterface.onEditDateClick()}"
android:text="@={editTaskViewModel.date}"
android:textSize="18sp" />
<View
android:id="@+id/line"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_below="@+id/date_text"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimaryDark" />
<TextView
android:id="@+id/edit_time_text"
android:layout_width="132dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="231dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select time"
android:onClick="@{()-> editTaskInterface.onEditTimeClick()}"
android:text="@={editTaskViewModel.time}"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/and"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="230dp"
android:gravity="center"
android:text="and"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<Button
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="115dp"
android:onClick="@{()-> editTaskInterface.onEditClick()}"
android:text="Edit" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
EditTaskActivity:
public class EditTaskActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {
private String TAG;
public EditTaskActivityBinding editTaskActivityBinding;
private MainViewModel mainViewModel;
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editTaskActivityBinding = DataBindingUtil.setContentView(this, R.layout.edit_task_activity);
mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
editTaskActivityBinding.setEditTaskViewModel(mainViewModel);
dateSetListener = (view, year, month, dayOfMonth) -> {
month = month + 1;
Log.d(TAG, "onDataSet: dd/mm/yyyy: " + year + "/" + month + "/" + dayOfMonth);
String date = dayOfMonth + "/" + month + "/" + year;
editTaskActivityBinding.editDateText.setText(date);
};
timeSetListener = (view, hourOfDay, minute) -> {
Log.d(TAG, "onTimeSet: hh/mm: " + hourOfDay + "/" + minute);
String time = hourOfDay + ":" + minute;
editTaskActivityBinding.editTimeText.setText(time);
};
editTaskActivityBinding.setEditTaskInterface(new OnEditTaskClickInterface() {
@Override
public void onEditClick() {
}
@Override
public void onEditDateClick() {
showDatePicker();
}
@Override
public void onEditTimeClick() {
showTimePicker();
}
});
}
public void showDatePicker() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, dateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
public void showTimePicker() {
Calendar calendar = Calendar.getInstance();
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog dialog = new TimePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, timeSetListener,
hourOfDay, minute, DateFormat.is24HourFormat(this));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
android android-databinding
|
show 2 more comments
How to set data in editexts with databinding from Viewmodel?
I'm passing parameters from the RecyclerView Item to the ViewModel in OnItemClick and in logs everything looks fine, but the Edittexts are still empty. when I tried to set the String created in ViewModel and was the same. EditTexts are still empty. I no have idea where is error.
ViewModel:
public class MainViewModel extends AndroidViewModel implements RecyclerViewAdapter.OnItemClickListener {
private TaskRepository taskRepository;
private LiveData<List<Task>> allTasks;
public ObservableField<String> description = new ObservableField<>();
public ObservableField<String> date = new ObservableField<>();
public ObservableField<String> time = new ObservableField<>();
String TAG;
public MainViewModel(@NonNull Application application) {
super(application);
taskRepository = new TaskRepository(application);
allTasks = taskRepository.getAllTasks();
}
public LiveData<List<Task>> getAllTasks() {
return allTasks;
}
public void deleteTask(Task task) {
taskRepository.delete(task);
}
@Override
public void onItemClick(View view, Task item) {
Log.d(TAG, "MVM " + view + " / " + item.getDescription() + " / " + item.getDate() + " / " + item.getTime());
description.set(item.getDescription());
date.set(item.getDate());
time.set(item.getTime());
}
XML file:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="editTaskViewModel"
type="com.example.daniellachacz.taskmvvm.viewmodel.MainViewModel">
</variable>
<variable
name="editTaskInterface"
type="com.example.daniellachacz.taskmvvm.view.OnEditTaskClickInterface">
</variable>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/title"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:clickable="false"
android:focusable="false"
android:text="Edit task"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="25sp" />
<EditText
android:id="@+id/edit_description_text"
android:layout_width="320dp"
android:layout_height="40dp"
android:layout_below="@+id/title"
android:layout_alignStart="@+id/title"
android:backgroundTint="#FFF"
android:text="@={editTaskViewModel.description}"
android:textColor="#FFF"
android:textColorHint="#949393"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/edit_date_text"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/edit_time_text"
android:layout_marginStart="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select date"
android:onClick="@{()-> editTaskInterface.onEditDateClick()}"
android:text="@={editTaskViewModel.date}"
android:textSize="18sp" />
<View
android:id="@+id/line"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_below="@+id/date_text"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimaryDark" />
<TextView
android:id="@+id/edit_time_text"
android:layout_width="132dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="231dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select time"
android:onClick="@{()-> editTaskInterface.onEditTimeClick()}"
android:text="@={editTaskViewModel.time}"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/and"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="230dp"
android:gravity="center"
android:text="and"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<Button
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="115dp"
android:onClick="@{()-> editTaskInterface.onEditClick()}"
android:text="Edit" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
EditTaskActivity:
public class EditTaskActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {
private String TAG;
public EditTaskActivityBinding editTaskActivityBinding;
private MainViewModel mainViewModel;
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editTaskActivityBinding = DataBindingUtil.setContentView(this, R.layout.edit_task_activity);
mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
editTaskActivityBinding.setEditTaskViewModel(mainViewModel);
dateSetListener = (view, year, month, dayOfMonth) -> {
month = month + 1;
Log.d(TAG, "onDataSet: dd/mm/yyyy: " + year + "/" + month + "/" + dayOfMonth);
String date = dayOfMonth + "/" + month + "/" + year;
editTaskActivityBinding.editDateText.setText(date);
};
timeSetListener = (view, hourOfDay, minute) -> {
Log.d(TAG, "onTimeSet: hh/mm: " + hourOfDay + "/" + minute);
String time = hourOfDay + ":" + minute;
editTaskActivityBinding.editTimeText.setText(time);
};
editTaskActivityBinding.setEditTaskInterface(new OnEditTaskClickInterface() {
@Override
public void onEditClick() {
}
@Override
public void onEditDateClick() {
showDatePicker();
}
@Override
public void onEditTimeClick() {
showTimePicker();
}
});
}
public void showDatePicker() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, dateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
public void showTimePicker() {
Calendar calendar = Calendar.getInstance();
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog dialog = new TimePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, timeSetListener,
hourOfDay, minute, DateFormat.is24HourFormat(this));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
android android-databinding
stacktrace please
– Basi
Nov 16 '18 at 12:14
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
Could you add activity/fragment whereMainViewModel
is used?
– ConstOrVar
Nov 16 '18 at 12:50
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46
|
show 2 more comments
How to set data in editexts with databinding from Viewmodel?
I'm passing parameters from the RecyclerView Item to the ViewModel in OnItemClick and in logs everything looks fine, but the Edittexts are still empty. when I tried to set the String created in ViewModel and was the same. EditTexts are still empty. I no have idea where is error.
ViewModel:
public class MainViewModel extends AndroidViewModel implements RecyclerViewAdapter.OnItemClickListener {
private TaskRepository taskRepository;
private LiveData<List<Task>> allTasks;
public ObservableField<String> description = new ObservableField<>();
public ObservableField<String> date = new ObservableField<>();
public ObservableField<String> time = new ObservableField<>();
String TAG;
public MainViewModel(@NonNull Application application) {
super(application);
taskRepository = new TaskRepository(application);
allTasks = taskRepository.getAllTasks();
}
public LiveData<List<Task>> getAllTasks() {
return allTasks;
}
public void deleteTask(Task task) {
taskRepository.delete(task);
}
@Override
public void onItemClick(View view, Task item) {
Log.d(TAG, "MVM " + view + " / " + item.getDescription() + " / " + item.getDate() + " / " + item.getTime());
description.set(item.getDescription());
date.set(item.getDate());
time.set(item.getTime());
}
XML file:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="editTaskViewModel"
type="com.example.daniellachacz.taskmvvm.viewmodel.MainViewModel">
</variable>
<variable
name="editTaskInterface"
type="com.example.daniellachacz.taskmvvm.view.OnEditTaskClickInterface">
</variable>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/title"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:clickable="false"
android:focusable="false"
android:text="Edit task"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="25sp" />
<EditText
android:id="@+id/edit_description_text"
android:layout_width="320dp"
android:layout_height="40dp"
android:layout_below="@+id/title"
android:layout_alignStart="@+id/title"
android:backgroundTint="#FFF"
android:text="@={editTaskViewModel.description}"
android:textColor="#FFF"
android:textColorHint="#949393"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/edit_date_text"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/edit_time_text"
android:layout_marginStart="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select date"
android:onClick="@{()-> editTaskInterface.onEditDateClick()}"
android:text="@={editTaskViewModel.date}"
android:textSize="18sp" />
<View
android:id="@+id/line"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_below="@+id/date_text"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimaryDark" />
<TextView
android:id="@+id/edit_time_text"
android:layout_width="132dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="231dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select time"
android:onClick="@{()-> editTaskInterface.onEditTimeClick()}"
android:text="@={editTaskViewModel.time}"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/and"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="230dp"
android:gravity="center"
android:text="and"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<Button
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="115dp"
android:onClick="@{()-> editTaskInterface.onEditClick()}"
android:text="Edit" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
EditTaskActivity:
public class EditTaskActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {
private String TAG;
public EditTaskActivityBinding editTaskActivityBinding;
private MainViewModel mainViewModel;
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editTaskActivityBinding = DataBindingUtil.setContentView(this, R.layout.edit_task_activity);
mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
editTaskActivityBinding.setEditTaskViewModel(mainViewModel);
dateSetListener = (view, year, month, dayOfMonth) -> {
month = month + 1;
Log.d(TAG, "onDataSet: dd/mm/yyyy: " + year + "/" + month + "/" + dayOfMonth);
String date = dayOfMonth + "/" + month + "/" + year;
editTaskActivityBinding.editDateText.setText(date);
};
timeSetListener = (view, hourOfDay, minute) -> {
Log.d(TAG, "onTimeSet: hh/mm: " + hourOfDay + "/" + minute);
String time = hourOfDay + ":" + minute;
editTaskActivityBinding.editTimeText.setText(time);
};
editTaskActivityBinding.setEditTaskInterface(new OnEditTaskClickInterface() {
@Override
public void onEditClick() {
}
@Override
public void onEditDateClick() {
showDatePicker();
}
@Override
public void onEditTimeClick() {
showTimePicker();
}
});
}
public void showDatePicker() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, dateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
public void showTimePicker() {
Calendar calendar = Calendar.getInstance();
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog dialog = new TimePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, timeSetListener,
hourOfDay, minute, DateFormat.is24HourFormat(this));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
android android-databinding
How to set data in editexts with databinding from Viewmodel?
I'm passing parameters from the RecyclerView Item to the ViewModel in OnItemClick and in logs everything looks fine, but the Edittexts are still empty. when I tried to set the String created in ViewModel and was the same. EditTexts are still empty. I no have idea where is error.
ViewModel:
public class MainViewModel extends AndroidViewModel implements RecyclerViewAdapter.OnItemClickListener {
private TaskRepository taskRepository;
private LiveData<List<Task>> allTasks;
public ObservableField<String> description = new ObservableField<>();
public ObservableField<String> date = new ObservableField<>();
public ObservableField<String> time = new ObservableField<>();
String TAG;
public MainViewModel(@NonNull Application application) {
super(application);
taskRepository = new TaskRepository(application);
allTasks = taskRepository.getAllTasks();
}
public LiveData<List<Task>> getAllTasks() {
return allTasks;
}
public void deleteTask(Task task) {
taskRepository.delete(task);
}
@Override
public void onItemClick(View view, Task item) {
Log.d(TAG, "MVM " + view + " / " + item.getDescription() + " / " + item.getDate() + " / " + item.getTime());
description.set(item.getDescription());
date.set(item.getDate());
time.set(item.getTime());
}
XML file:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="editTaskViewModel"
type="com.example.daniellachacz.taskmvvm.viewmodel.MainViewModel">
</variable>
<variable
name="editTaskInterface"
type="com.example.daniellachacz.taskmvvm.view.OnEditTaskClickInterface">
</variable>
</data>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@color/colorPrimaryDark">
<TextView
android:id="@+id/title"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:clickable="false"
android:focusable="false"
android:text="Edit task"
android:textAlignment="center"
android:textColor="#FFF"
android:textSize="25sp" />
<EditText
android:id="@+id/edit_description_text"
android:layout_width="320dp"
android:layout_height="40dp"
android:layout_below="@+id/title"
android:layout_alignStart="@+id/title"
android:backgroundTint="#FFF"
android:text="@={editTaskViewModel.description}"
android:textColor="#FFF"
android:textColorHint="#949393"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="@+id/edit_date_text"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/edit_time_text"
android:layout_marginStart="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select date"
android:onClick="@{()-> editTaskInterface.onEditDateClick()}"
android:text="@={editTaskViewModel.date}"
android:textSize="18sp" />
<View
android:id="@+id/line"
android:layout_width="320dp"
android:layout_height="1dp"
android:layout_below="@+id/date_text"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimaryDark" />
<TextView
android:id="@+id/edit_time_text"
android:layout_width="132dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="231dp"
android:layout_marginEnd="40dp"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:hint="Select time"
android:onClick="@{()-> editTaskInterface.onEditTimeClick()}"
android:text="@={editTaskViewModel.time}"
android:textAlignment="center"
android:textSize="18sp" />
<TextView
android:id="@+id/and"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginTop="230dp"
android:gravity="center"
android:text="and"
android:textColor="@color/colorPrimaryDark"
android:textSize="18sp" />
<Button
android:id="@+id/edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="115dp"
android:onClick="@{()-> editTaskInterface.onEditClick()}"
android:text="Edit" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
EditTaskActivity:
public class EditTaskActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {
private String TAG;
public EditTaskActivityBinding editTaskActivityBinding;
private MainViewModel mainViewModel;
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
editTaskActivityBinding = DataBindingUtil.setContentView(this, R.layout.edit_task_activity);
mainViewModel = ViewModelProviders.of(this).get(MainViewModel.class);
editTaskActivityBinding.setEditTaskViewModel(mainViewModel);
dateSetListener = (view, year, month, dayOfMonth) -> {
month = month + 1;
Log.d(TAG, "onDataSet: dd/mm/yyyy: " + year + "/" + month + "/" + dayOfMonth);
String date = dayOfMonth + "/" + month + "/" + year;
editTaskActivityBinding.editDateText.setText(date);
};
timeSetListener = (view, hourOfDay, minute) -> {
Log.d(TAG, "onTimeSet: hh/mm: " + hourOfDay + "/" + minute);
String time = hourOfDay + ":" + minute;
editTaskActivityBinding.editTimeText.setText(time);
};
editTaskActivityBinding.setEditTaskInterface(new OnEditTaskClickInterface() {
@Override
public void onEditClick() {
}
@Override
public void onEditDateClick() {
showDatePicker();
}
@Override
public void onEditTimeClick() {
showTimePicker();
}
});
}
public void showDatePicker() {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, dateSetListener,
year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
public void showTimePicker() {
Calendar calendar = Calendar.getInstance();
int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
TimePickerDialog dialog = new TimePickerDialog(this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, timeSetListener,
hourOfDay, minute, DateFormat.is24HourFormat(this));
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
android android-databinding
android android-databinding
edited Nov 16 '18 at 14:46
user9897182
asked Nov 16 '18 at 12:09
user9897182user9897182
458
458
stacktrace please
– Basi
Nov 16 '18 at 12:14
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
Could you add activity/fragment whereMainViewModel
is used?
– ConstOrVar
Nov 16 '18 at 12:50
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46
|
show 2 more comments
stacktrace please
– Basi
Nov 16 '18 at 12:14
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
Could you add activity/fragment whereMainViewModel
is used?
– ConstOrVar
Nov 16 '18 at 12:50
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46
stacktrace please
– Basi
Nov 16 '18 at 12:14
stacktrace please
– Basi
Nov 16 '18 at 12:14
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
Could you add activity/fragment where
MainViewModel
is used?– ConstOrVar
Nov 16 '18 at 12:50
Could you add activity/fragment where
MainViewModel
is used?– ConstOrVar
Nov 16 '18 at 12:50
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337635%2fnull-editexts-in-databinding-activity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337635%2fnull-editexts-in-databinding-activity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stacktrace please
– Basi
Nov 16 '18 at 12:14
have you debugged your code ?. And take a look at your logs maybe you can find the problem.
– Umair
Nov 16 '18 at 12:20
Could you add activity/fragment where
MainViewModel
is used?– ConstOrVar
Nov 16 '18 at 12:50
@Umair Yes. I have the parameters in ViewModel. I also set normal String created in method and the Textviews are empty.
– user9897182
Nov 16 '18 at 14:44
@ConstOrVar I just pasted code in my main comment.
– user9897182
Nov 16 '18 at 14:46