1

I currently have 4 EditTexts in every item in the RecyclerView.

The scenario is: The user fills up only 2/4 of the EditTexts on the item(n) and proceeds to the item(n), fills up everything on the item(n) and clicks the submit button.

There should be a message dialog that there is an EditText that hasn’t yet been filled up.

How can I know that there is still a remaining EditText that hasn't yet been fill up on every item?

@Override
public void onBindViewHolder(final CreditCard_PostPayAdapter.MyViewHolder holder,int position) {
    final int pos = position;
    //final AccountDetailsItem accountDetailsItem = accountDetailsItemList.get(position);   

    button.setOnClickNewListener(new onClickListener)
    {
        //Checks if edittext1,edittext2,editext3,edittext4 of item(n)/item(pos) have value or null.
        //if all edittext in item(n) have values then proceed to the next item.
    }
}

public class MyViewHolder extends RecyclerView.ViewHolder {

    public ediText editText1,editText2,editText3,editText4
    public ImageButton mDeleteButton;
    public MyViewHolder(View view) {
        super(view);
        this.editText1 = view.findViewByiId(myedittext1);
           this.editText2 = view.findViewByiId(myedittext2);
              this.editText3= view.findViewByiId(myedittext3);
                 this.editText4 = view.findViewByiId(myedittext4);
    }
}

XML:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_overflow"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/item_ripple"
    android:clickable="true"
    android:focusable="true"
    android:foregroundGravity="center_horizontal"
    android:orientation="vertical"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:fillViewport="true"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="wrap_content">

            <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="horizontal"
                android:background="#ffffff"
                android:layout_width="match_parent"
                android:layout_height="50dp">

                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="16dp"
                    android:layout_marginLeft="8dp"
                    android:id="@+id/mDeleteButton"
                    android:background="@android:color/transparent"
                    android:src="@drawable/btn_delete_documentpic"/>
                <TextView
                    android:id="@+id/header_title"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:layout_marginTop="15dp"
                    android:text="@string/lorem_ipsum_short"
                    android:textColor="@color/aub_red_new"
                    android:textSize="20sp"
                    android:layout_marginLeft="4dp"

                    android:textStyle="bold" />

                <ImageView
                    android:layout_weight=".2"
                    android:src="@drawable/ic_up_black"
                    android:layout_width="0dp"
                    android:padding="12dp"
                    android:layout_height="50dp"
                    android:id="@+id/arrow_indicator"/>
            </LinearLayout>
            <View
                android:id="@+id/mHeaderDivider"
                android:layout_width="match_parent"
                android:layout_height=".8dp"
                android:alpha="0.8"
                android:layout_marginBottom="16dp"
                android:background="#CACACA"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/mBodyLinear"
                android:orientation="vertical">

                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginTop="16dp"
                    app:counterTextAppearance="@style/counterText"
                    app:counterOverflowTextAppearance="@style/counterOverride"
                    app:theme="@style/TextInputLayoutGold">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/mMerchantNameTextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:textSize="@dimen/font_size"
                        android:inputType ="numberDecimal"
                        app:theme="@style/EditTextGold"
                        android:hint="@string/label_merchant_name"
                        />
                </android.support.design.widget.TextInputLayout>
                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    app:counterTextAppearance="@style/counterText"
                    app:counterOverflowTextAppearance="@style/counterOverride"
                    app:theme="@style/TextInputLayoutGold">

                    <android.support.design.widget.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:textSize="@dimen/font_size"
                        android:inputType ="numberDecimal"
                        app:theme="@style/EditTextGold"
                        android:hint="@string/hint_transaction_amount"
                        />
                </android.support.design.widget.TextInputLayout>

     <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    android:layout_marginTop="16dp"
                    app:counterTextAppearance="@style/counterText"
                    app:counterOverflowTextAppearance="@style/counterOverride"
                    app:theme="@style/TextInputLayoutGold">

                    <android.support.design.widget.TextInputEditText
                        android:id="@+id/mMerchantNameTextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:textSize="@dimen/font_size"
                        android:inputType ="numberDecimal"
                        app:theme="@style/EditTextGold"
                        android:hint="@string/label_merchant_name"
                        />
                </android.support.design.widget.TextInputLayout>
                <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="16dp"
                    app:counterTextAppearance="@style/counterText"
                    app:counterOverflowTextAppearance="@style/counterOverride"
                    app:theme="@style/TextInputLayoutGold">

                    <android.support.design.widget.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:textSize="@dimen/font_size"
                        android:inputType ="numberDecimal"
                        app:theme="@style/EditTextGold"
                        android:hint="@string/hint_transaction_amount"
                        />
                </android.support.design.widget.TextInputLayout>

            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>
0xCursor
  • 2,242
  • 4
  • 15
  • 33

2 Answers2

3

I don’t know exactly what you are looking for, but you could do:

String editTextStr = editText.getText().toString();

if (editTextStr.equals(""))
{
    // editText is empty
}

for each of your EditTexts to check if they are empty or not.

If you wanted a boolean value of if an EditText is empty, you could try:

boolean isEditTextEmpty = editText.getText().toString().isEmpty();
0xCursor
  • 2,242
  • 4
  • 15
  • 33
0

I think TextWatcher could do the job here. It fires on every stroke of the key on EditText. From there, you could check if other EditTexts have been filled or not and act accordingly. Do note that the listener fires on every key stroke, you need to handle the action correctly.

This post here give you some similar idea.

myTextBox.addTextChangedListener(new TextWatcher() {  

    public void afterTextChanged(Editable s) {}  

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 

    public void onTextChanged(CharSequence s, int start, int before, int count) {  
    //your code here
    }
});

android edittext onchange listener

hjchin
  • 864
  • 2
  • 8
  • 25
  • This won't help because i need to check everything in the submit button than having a textwatcher –  Jul 10 '18 at 03:49
  • please share more info, I looked at the code, where is the button of button.setOnClick being created? – hjchin Jul 10 '18 at 03:53
  • if possible, post the complete adapter and xml file for better understanding. – hjchin Jul 10 '18 at 04:50
  • I still cannot tell the button creation of this button.setOnClickNewListener(new onClickListener). my guess is, this button is from activity, not adapter, i.e. not from MyViewHolder, the class and xml doesn't have it. If that is the case (button is created in activity, it is likely that and actually common to handle all interaction by using callback on activity, not the adapter itself. – hjchin Jul 10 '18 at 07:47