Reputation: 131
this is more than likely a very simple thing to do so I apologise if it is, but I cannot seem to implement it.
I am trying to check what a user types into a editText field and compare it against a hard coded string.
Here is the string that I want to compare against -
OverlayItem overlayitem = new OverlayItem(point,"House Information",
"4 Bed w/ large garden\n2 minute walk from Town Centre\nSchools 5 minute walk\n€300,000");
Here is my editText field -
<!-- Number of rooms text field -->
<EditText
android:id="@+id/numberRooms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="No. of rooms"
android:imeActionLabel="launch"
android:inputType="number" />
I want to be able to check what the user types against the "4" in the string. Here is what I have attempted so far -
EditText numberOfRooms = (EditText) findViewById(R.id.numberRooms);
if(overlayitem.equals(numberOfRooms.getText().toString()))
{
itemizedoverlay.addOverlay(overlayitem);
}
So basically I don't want to compare the whole string, I just want to compare what the user enters to the first character in the string, which in this case will always be a number.
Upvotes: 0
Views: 455
Reputation: 1455
Try:
String rooms = overlayitem.getSnippet().substring(0,2);
rooms = rooms.trim();
if(rooms.equals(numberOfRooms.getText().toString()))
{
//Do whatever you want
}
Upvotes: 1
Reputation: 5475
overlayitem is not a String.
You might want to compare overlayitem.getTitle()
or overlayitem.getSnippet()
instead:
overlayitem.getTitle().equals(numberOfRooms.getText().toString())
Upvotes: 0