Closed catkbm closed 7 years ago
Which class does your custom element inherit? If it's LabeledFieldController
, you just need to provide the validators to the super class. If you can describe in more detail what your custom element does, I can point you in the right direction.
Hai,
Below code is the Custom Element
package com.tt.uloor.utils;
import android.content.Context; import android.support.design.widget.TextInputLayout; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText;
import com.github.dkharrat.nexusdialog.controllers.LabeledFieldController; import com.tt.uloor.R; import com.tt.uloor.api.response.ShopDetailResponse;
public class CustomEditTextElement extends LabeledFieldController { private final String mHint; private final ShopDetailResponse.Result element; private Context mCtx;
public CustomEditTextElement(Context ctx, String name, String
textPlaceholder, ShopDetailResponse.Result element) { super(ctx, name, null, false); mCtx = ctx; mHint = textPlaceholder; this.element = element; }
@Override
protected View createFieldView() {
LayoutInflater inflater = (LayoutInflater)
mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.custom_edittext_element, null); TextInputLayout textInputLayout = (TextInputLayout) view.findViewById(R.id.value_layout); textInputLayout.setHint(mHint); return view; }
public ShopDetailResponse.Result getValue() {
return element;
}
public EditText getEditText() {
return (EditText) getView().findViewById(R.id.value);
}
public TextInputLayout getInputLayout() {
return (TextInputLayout) getView().findViewById(R.id.value_layout);
}
public void refresh() {
// nothing to refresh
}
}
Below code is the XML layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/value_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:id="@+id/value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.design.widget.TextInputLayout>
On Sun, Sep 17, 2017 at 8:07 PM, karthik kumar catkbm25@gmail.com wrote:
Hai,
Below code is the Custom Element
package com.tt.uloor.utils;
import android.content.Context; import android.support.design.widget.TextInputLayout; import android.view.LayoutInflater; import android.view.View; import android.widget.EditText;
import com.github.dkharrat.nexusdialog.controllers.LabeledFieldController; import com.tt.uloor.R; import com.tt.uloor.api.response.ShopDetailResponse;
public class CustomEditTextElement extends LabeledFieldController { private final String mHint; private final ShopDetailResponse.Result element; private Context mCtx;
public CustomEditTextElement(Context ctx, String name, String textPlaceholder, ShopDetailResponse.Result element) { super(ctx, name, null, false); mCtx = ctx; mHint = textPlaceholder; this.element = element; } @Override protected View createFieldView() { LayoutInflater inflater = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.custom_edittext_element, null); TextInputLayout textInputLayout = (TextInputLayout) view.findViewById(R.id.value_layout); textInputLayout.setHint(mHint); return view; } public ShopDetailResponse.Result getValue() { return element; } public EditText getEditText() { return (EditText) getView().findViewById(R.id.value); } public TextInputLayout getInputLayout() { return (TextInputLayout) getView().findViewById(R.id.value_layout); } public void refresh() { // nothing to refresh }
}
In this case, pass a set of validators to the LabeledFieldController
:
public CustomEditTextElement(Context ctx, String name, String textPlaceholder, ShopDetailResponse.Result element, Set<InputValidator> validators) {
super(ctx, name, null, validators);
mCtx = ctx;
mHint = textPlaceholder;
this.element = element;
}
For an example, on how to pass validators, see the 'samples' project included in the repo.
Thank you so much for your solution for the problem.
On Sun, Sep 17, 2017 at 10:49 PM, Dia Kharrat notifications@github.com wrote:
Closed #66 https://github.com/dkharrat/NexusDialog/issues/66.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dkharrat/NexusDialog/issues/66#event-1252545178, or mute the thread https://github.com/notifications/unsubscribe-auth/AGTDrFWVzANvV6JIeaTXyH5LkYEDs0gPks5sjVSPgaJpZM4PSPfU .
How can i set filed required validator for My custom element which is created by ownself.
Kindly let me know, thanks in advance