1
How do I make it so that when a button is pressed, it activates a function only if a specific word has been typed at any position in an Edittext? Thank you.
main.xml:
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:hint="Digite aqui..."
android:id="@+id/searchfield"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Botão"
android:id="@+id/btn"/>
Mainactivity.java:
Button btn = (Button)findViewById(R.id.btn);
final EditText search = (EditText)findViewById(R.id.searchfield);
go.setOnClickListener(new OnClickListener(){
public void onClick(View p1){
//O que devo colocar na condição if?
if(search.getText().toString()){
function();
}
}
});