В XML-файле вам нужно иметь EditText и Button , как показано ниже,
<EditText
android:id="@+id/txt"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Submit" />
И ваш код должен выглядеть следующим образом.
public void onCreate(Bundle savedInstanceState) {
// Initialize edittext and button
EditText txt = (EditText) findViewById(R.id.txt);
Button btn = (Button) findViewById(R.id.btn);
// Set listener to the button
btn.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
String text = txt.getText().toString();
yourFunction(text);
}
});
}
private void yourFunction(String text) {
// Your search code goes here
}