java - Accept user input from Activity -
i have experience java, trying create android app , not know how accept user input. id of edit text enterrequestmessage , name of xml file activity_score_entry.xml. here beginning of java file.
import android.support.v7.app.appcompatactivity; import android.os.bundle; public class scoreentry extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_score_entry); } }
you need access controls in 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 value here log.d(scoreentry.class.getcanonicalname(), "the value is: " + value); } } }
and in xml
<?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>
you can adjust code according needs.
Comments
Post a Comment