は、あなたがあなたのニーズに合わせてコードを調整することができます
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_score_entry"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
XML
public class ScoreEntry extends AppCompatActivity implements View.OnClickListener {
private EditText editText;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score_entry);
editText = (EditText) findViewById(R.id.editText);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.button) {
String value = editText.getText().toString();
// use the value here
Log.d(ScoreEntry.class.getCanonicalName(), "The value is: " + value);
}
}
}
にとXMLのコントロールへのアクセスを取得する必要があります。
いつユーザー入力を取得しますか? onValueChangeまたはボタンをクリックして – zombie
ああ、忘れました。私はこのボタンのボタンをクリックして取得したい:任意のヘルプ – mike
ボタンをonClickListener()を設定し、EditTextの値を確認してくれてありがとう。あなたがfindViewById()を知っているかのように、あなたは – zombie