0

In my android I have the xml file :-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:id="@+id/liner" >

    <EditText
        android:id="@+id/user"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <EditText
        android:id="@+id/partner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />

    <EditText
        android:id="@+id/home"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" />
</LinearLayout>

Now I have a string i.e String field =error.getmethod(); This string(field) may return user/name/partner/home.. I want to set error message according to edittext fields with their id's..I have done

 ViewGroup edittextviews = (ViewGroup) findViewById(R.id.liner);
                    for(int i=0; i < edittextviews.getChildCount(); i++) {
                    View childView = edittextviews.getChildAt(i);
                    if(childView.getText().toString()==field ){
                        childView.setError("here is an error");

                    }

                    }

But it is showing error...where is the problem???

user_apr
  • 719
  • 2
  • 10
  • 27
  • This thing is not for compareing.. – user_apr Mar 23 '15 at 14:16
  • But it is. You compare your strings using `==` when you should use `.equals()`. The latter checks the contents of the strings while the first checks for object equality which is not the same. Blackbelt is right. – Treeline Mar 23 '15 at 14:24

0 Answers0