I can't seem to get findViewById working with the EditText. It works fine with the button, but I think I am doing something wrong and I can't seem to find a solution anywhere. How does findViewById work with EditTexts?
Here is my class..
public class MainActivity extends ActionBarActivity {
Button sbutton;
EditText book, chapter, verse;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sbutton = (Button) findViewById(R.id.sbutton);
book = (EditText) findViewByID(R.id.book1);
chapter = (EditText) findViewByID(R.id.chapter1);
verse = (EditText) findViewByID(R.id.verse1);
}
}
And here is my XML...
<TextView android:text="Please enter your favorite scripture" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/book1"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chapter1"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/verse1"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/sbutton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="77dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Book"
android:id="@+id/textView2"
android:layout_alignTop="@+id/book"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chapter"
android:id="@+id/textView3"
android:layout_below="@+id/book"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Verse"
android:id="@+id/textView4"
android:layout_below="@+id/chapter"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
I know this might not be the nicest code because I'm brand new to Android Studio. I would appreciate a little help understanding how this method works and what I might be doing wrong here. Thanks!
Aucun commentaire:
Enregistrer un commentaire