java - I cannot figure out how to grab input from EditText to pass to another file -


i have user type in information such upc in edittext box , click button next it. how can text box pass other activity when click button? i'm assuming use intent launch activity.

the edit text element:

<edittext     android:id="@+id/edittext1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/textview1"     android:cursorvisible="true"     android:ems="10"     android:inputtype="text" /> 

code search button:

<button     android:id="@+id/button2"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/edittext1"     android:layout_below="@+id/textview1"     android:layout_torightof="@+id/textview1"     android:onclick="onclicksearch"     android:text="@string/search" /> 

code in main.java:

public void onclicksearch(view view) {           string upc = r.id.edittext1.gettext().tostring();         intent intent = new intent("net.example.glutefree.networking");            intent.putextra("upca", upc);  //text key used retrieve value in nextactivity          startactivity(intent);     } 

if need anymore code let me know

ok, off start, important parts to:

1) reference edittext object in activity code:

private edittext mmyedittext; 

which should initialized during oncreate this:

mmyedittext = (edittext) findviewbyid(r.id.edittext1); 

2) handle click:

public void onclicksearch(view view) {       //string upc = r.id.edittext1.gettext().tostring();      string upc = mmyedittext.gettext().tostring();     //intent intent = new intent("net.example.glutefree.networking");        intent intent = new intent(this, yourotherclass.class);     intent.putextra("upca", upc);  //text key used retrieve value in nextactivity      startactivity(intent); } 

the difference calling gettext on identifier: r.id.edittext1, int, now, accessing actual instance of edittext.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -