RecyclerView EditText-检查它是否具有值或为null

时间:2018-07-10 03:05:57

标签: android android-recyclerview

我目前在EditText中的每个项目中有4个RecyclerView

方案是:用户仅填充项目(n)上EditText的2/4,然后继续进行项目(n),填充项目(n)上的所有内容,然后单击提交按钮。

应该出现一个消息对话框,提示尚未填写的EditText

我怎么知道还有剩余的EditText尚未填满每个项目?

@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>

2 个答案:

答案 0 :(得分:2)

我不确定您要寻找的是什么,但是您可以:

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

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

为您的每个EditText检查它们是否为空。

如果您想要一个boolean为空的EditText值,则可以尝试:

boolean isEditTextEmpty = editText.getText().toString().isEmpty();

答案 1 :(得分:0)

我认为TextWatcher可以在这里完成这项工作。它会在EditText上的每个键击时触发。从那里,您可以检查是否已填充其他EditText,并采取相应的措施。请注意,监听器会在每次击键时触发,您需要正确处理操作。

这里的帖子给你一些类似的想法。

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