Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- xmlns:android="http://schemas.android.com/apk/res/android">
- <EditText
- android:id="@+id/voice_edittext"
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:hint="Add answer here"
- />
- <ImageButton
- android:id="@+id/microphone_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_mic_black_24dp"
- />
- <ImageButton
- android:id="@+id/delete_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/ic_cancel_black_24dp"
- android:visibility="gone"
- />
- </LinearLayout>
- <com.sunilson.quizcreator.presentation.views.EditTextWithVoiceInput
- android:id="@+id/form_question"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="10dp"
- android:layout_marginTop="10dp"
- app:editTextValue="@={viewModel.observableText}"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- @BindingAdapter("editTextValueAttrChanged")
- fun setListener(editTextWithVoiceInput: EditTextWithVoiceInput, listener: InverseBindingListener) {
- editTextWithVoiceInput.voice_edittext.addTextChangedListener(object : TextWatcher {
- override fun afterTextChanged(p0: Editable?) {
- listener.onChange()
- }
- override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
- override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
- })
- }
- @BindingAdapter("editTextValue")
- fun setTextValue(editTextWithVoiceInput: EditTextWithVoiceInput, value: String?) {
- if (value != editTextWithVoiceInput.voice_edittext.text.toString()) editTextWithVoiceInput.voice_edittext.setText(value)
- }
- @InverseBindingAdapter(attribute = "editTextValue")
- fun getTextValue(editTextWithVoiceInput: EditTextWithVoiceInput): String? {
- return editTextWithVoiceInput.voice_edittext.text.toString()
- }
- class EditTextWithVoiceInput(context: Context, attributeSet: AttributeSet) : LinearLayout(context, attributeSet) {
- init {
- val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
- val view = inflater.inflate(R.layout.voice_edittext, this, true)
- view.microphone_button.setOnTouchListener { p0, p1 ->
- ...
- }
- }
- }
- java.lang.NullPointerException: Attempt to invoke virtual method 'void <MY_PACKAGE_NAME>.EditTextWithVoiceInput.setTag(java.lang.Object)' on a null object reference
Add Comment
Please, Sign In to add comment