单击按钮验证可扩展列表视图的子(edittext)

时间:2016-04-16 05:16:33

标签: android

我有一个片段和三个布局,因为我需要使用可扩展列表视图。第一个布局具有可扩展列表视图和提交按钮,第二个布局是具有文本视图的父级,第三个布局用于具有编辑文本的子级。现在我想在点击提交按钮时设置编辑文本的验证。我怎么能这样做?

fragment_contact_details.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<fr.castorflex.android.smoothprogressbar.SmoothProgressBar
    android:id="@+id/pocketProgressBar"
    style="@style/PocketProgressBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="-7dp"
    android:layout_marginTop="-7dp"
    android:indeterminate="true"
    android:visibility="invisible" />

<ExpandableListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:dividerHeight="4dp"/>

    <Button

        android:id="@+id/submit_btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Submit"
        android:textColor="@color/white"
        android:textSize="20sp"
        android:background="@color/md_blue_900"
        android:layout_alignParentTop="true" />

</LinearLayout>

fragment_contacts_details_child.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<fr.castorflex.android.smoothprogressbar.SmoothProgressBar
    android:id="@+id/pocketProgressBar"
    style="@style/PocketProgressBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="-7dp"
    android:layout_marginTop="-7dp"
    android:indeterminate="true"
    android:visibility="invisible" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateLayoutChanges="true"
    android:gravity="center_horizontal"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/til_item"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceSmall"
        app:hintTextAppearance="@style/CustomTextInputLayout">

        <EditText
            android:id="@+id/item"
            android:layout_width="280dp"
            android:layout_height="wrap_content"
            android:ems="10"
            android:gravity="center"
            android:inputType="text"
            android:maxLength="25"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/red"
            android:textColorHint="@color/md_green_400"
            app:hintTextAppearance="@style/CustomTextInputLayout"
            android:theme="@style/CustomEditText">

        </EditText>
    </android.support.design.widget.TextInputLayout>

    </LinearLayout>

</LinearLayout>

fragment_contact_details_parent.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/textViewParent"
    android:textStyle="normal"
    android:textColor="@color/card_background"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:paddingBottom="10dp"
    android:paddingTop="10dp"
    android:paddingLeft="40dp"
    android:background="@color/primary"/>

</LinearLayout>

ContactFragment.java

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = getActivity();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.fragment_contact_details, container, false);
    ExpandableListView elv = (ExpandableListView) mView.findViewById(R.id.list);
    submit= (Button)mView.findViewById(R.id.submit_btn);
    submit.setOnClickListener(this);
   // initViews();
    prepareListData();
    listAdapter = new ExpandableListAdapter(mContext, listDataHeader,listDataChild);
    elv.setAdapter(listAdapter);
    elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            return false;
        }
    });

    // Listview Group expanded listener
    elv.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {

        @Override
        public void onGroupExpand(int groupPosition) {
        }
    });

    // Listview Group collasped listener
    elv.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {

        @Override
        public void onGroupCollapse(int groupPosition) {

        }
    });

    // Listview on child click listener
    elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v,
                                    int groupPosition, int childPosition, long id) {
            // TODO Auto-generated method stub
            Toast.makeText(
                    mContext,
                    listDataHeader.get(groupPosition)
                            + " : "
                            + listDataChild.get(
                            listDataHeader.get(groupPosition)).get(
                            childPosition), Toast.LENGTH_SHORT)
                    .show();
            return false;
        }
    });


return mView;
}

/*
 * Preparing the list data
 */
private void prepareListData() {
    listDataHeader = new ArrayList<String>();
    listDataChild = new HashMap<String, List<String>>();

    // Adding child data
    listDataHeader.add("Personal Details");
    listDataHeader.add("Company Details");
    listDataHeader.add("Contact Information");
    listDataHeader.add("Miscellaneous");

    // Adding child data
    List<String> personalDetails = new ArrayList<String>();
    personalDetails.add(" ");
    personalDetails.add(" ");
    personalDetails.add(" ");
    personalDetails.add(" ");

    List<String> companyDetails = new ArrayList<String>();
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");
    companyDetails.add(" ");

    List<String> contactInformation = new ArrayList<String>();
    contactInformation.add(" ");
    contactInformation.add(" ");
    contactInformation.add(" ");
    contactInformation.add(" ");
    contactInformation.add(" ");
    contactInformation.add(" ");
    contactInformation.add(" ");

    List<String> miscellaneous = new ArrayList<String>();
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");
    miscellaneous.add(" ");

    listDataChild.put(listDataHeader.get(0), personalDetails); // Header, Child data
    listDataChild.put(listDataHeader.get(1), companyDetails);
    listDataChild.put(listDataHeader.get(2), contactInformation);
    listDataChild.put(listDataHeader.get(3), miscellaneous);
}

ExpandableListAdapter

@Override
public View getChildView(int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    final String childText = (String) getChild(groupPosition, childPosition);


    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.fragment_contact_details_child, null);
    }

    editetext = (EditText) convertView .findViewById(R.id.item);
    textinput= (TextInputLayout) convertView.findViewById(R.id.til_item);

    switch (groupPosition) {
        case 0:
        switch (childPosition) {
            case 0:
                textinput.setHint("Contact Person *");
                break;
            case 1:
                textinput.setHint("Contact Person Photo");
                break;
            case 2:
                textinput.setHint("Designation/Job *");
                break;
            case 3:
                textinput.setHint("CEO Name");
                break;
        }
            break;
        case 1:
            switch (childPosition) {
                case 0:
                    textinput.setHint("Company Name *");
                    break;
                case 1:
                    textinput.setHint("Country");
                    break;
                case 2:
                    textinput.setHint("City *");
                    break;
                case 3:
                    textinput.setHint("State *");
                    break;
                case 4:
                    textinput.setHint("Locality *");
                    break;
                case 5:
                    textinput.setHint("Postal Code *");
                    break;
                case 6:
                    textinput.setHint("Address 1 *");
                    break;
                case 7:
                    textinput.setHint("Address 2 *");
                    break;
                case 8:
                    textinput.setHint("Area/Landmark *");
                    break;
            }
            break;
        case 2:
            switch (childPosition) {
                case 0:
                    textinput.setHint("Contact Person_Telephone 1");
                    break;
                case 1:
                    textinput.setHint("Primary Mobile 1 *");
                    break;
                case 2:
                    textinput.setHint("Mobile 2");
                    break;
                case 3:
                    textinput.setHint("Fax 1");
                    break;
                case 4:
                    textinput.setHint("Fax 2");
                    break;
                case 5:
                    textinput.setHint("Primary Email *");
                    break;
                case 6:
                    textinput.setHint("Alternate Email");
                    break;
            }
            break;
        case 3: switch (childPosition) {
            case 0:
                textinput.setHint("Legal Owner");
                break;
            case 1:
                textinput.setHint("Legal Owner Designation");
                break;
            case 2:
                textinput.setHint("Head Office Size");
                break;
            case 3:
                textinput.setHint("Have you attended or plan to attend the trade show?");
                break;
            case 4:
                textinput.setHint("Language Spoken");
                break;
            case 5:
                textinput.setHint("Date Of Birth");
                break;
            case 6:
                textinput.setHint("Mobile Portal *");
                break;
            case 7:
                textinput.setHint("Email ID Portal *");
                break;
            case 8:
                textinput.setHint("T&C *");
                break;
            case 9:
                textinput.setHint("Signature *");
                break;
        }
            break;
    }
    editetext.addTextChangedListener(this);
    editTextList.add(editetext);

    return convertView;
}

0 个答案:

没有答案