Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. <LinearLayout
  2. android:layout_width="match_parent"
  3. android:layout_height="wrap_content"
  4. android:orientation="horizontal"
  5. xmlns:android="http://schemas.android.com/apk/res/android">
  6.  
  7. <EditText
  8. android:id="@+id/voice_edittext"
  9. android:layout_width="0dp"
  10. android:layout_weight="1"
  11. android:layout_height="wrap_content"
  12. android:hint="Add answer here"
  13. />
  14.  
  15. <ImageButton
  16. android:id="@+id/microphone_button"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:src="@drawable/ic_mic_black_24dp"
  20. />
  21. <ImageButton
  22. android:id="@+id/delete_button"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:src="@drawable/ic_cancel_black_24dp"
  26. android:visibility="gone"
  27. />
  28. </LinearLayout>
  29.  
  30. <com.sunilson.quizcreator.presentation.views.EditTextWithVoiceInput
  31. android:id="@+id/form_question"
  32. android:layout_width="match_parent"
  33. android:layout_height="wrap_content"
  34. android:layout_marginBottom="10dp"
  35. android:layout_marginTop="10dp"
  36. app:editTextValue="@={viewModel.observableText}"
  37. app:layout_constraintLeft_toLeftOf="parent"
  38. app:layout_constraintTop_toTopOf="parent" />
  39.  
  40. @BindingAdapter("editTextValueAttrChanged")
  41. fun setListener(editTextWithVoiceInput: EditTextWithVoiceInput, listener: InverseBindingListener) {
  42. editTextWithVoiceInput.voice_edittext.addTextChangedListener(object : TextWatcher {
  43. override fun afterTextChanged(p0: Editable?) {
  44. listener.onChange()
  45. }
  46.  
  47. override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
  48. override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
  49. })
  50. }
  51.  
  52. @BindingAdapter("editTextValue")
  53. fun setTextValue(editTextWithVoiceInput: EditTextWithVoiceInput, value: String?) {
  54. if (value != editTextWithVoiceInput.voice_edittext.text.toString()) editTextWithVoiceInput.voice_edittext.setText(value)
  55. }
  56.  
  57. @InverseBindingAdapter(attribute = "editTextValue")
  58. fun getTextValue(editTextWithVoiceInput: EditTextWithVoiceInput): String? {
  59. return editTextWithVoiceInput.voice_edittext.text.toString()
  60. }
  61.  
  62. class EditTextWithVoiceInput(context: Context, attributeSet: AttributeSet) : LinearLayout(context, attributeSet) {
  63.  
  64. init {
  65. val inflater = context?.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
  66. val view = inflater.inflate(R.layout.voice_edittext, this, true)
  67.  
  68. view.microphone_button.setOnTouchListener { p0, p1 ->
  69. ...
  70. }
  71. }
  72. }
  73.  
  74. 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