Skip to content Skip to sidebar Skip to footer

Displaying Text In An Android Studio Project

Trying to get a program similar to this to work on the android platform. The trouble is I'm not sure on using xml to display text/read user input. I'm fairly new to mobile software

Solution 1:

Yes, you generally use TextView for displaying text, and edit text for text for the user to input.

This is a good link to look at: http://developer.android.com/training/basics/firstapp/building-ui.html

The developer.android training articles are very good, even for a beginner. Use the xml file in the res/layout folder for your UI stuff. Android Studio even let's you see how your UI will look if you click on the Design tab at the bottom.

Side Note: You'll find it's a lot more fun than System.out.println()

Solution 2:

First in android you need to define a layout. Use:

  • EditText to replace inputs of the user (Scanner)
  • TextView to replace outputs to the user (System.out.println)

<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/some_label_text"/><EditTextandroid:id="@+id/example_input"android:hint="@string/some_hint_text"android:layout_width="wrap_content"android:layout_height="wrap_content" />

NOTE: Labels, if text is predefined, can have the text in the definition.

Second reference your objects into your java app by id like this.

EditTextexampleInput= (EditText )dialogCarro.findViewById(R.id.example_input);

Third you will need to add Listeners to Buttons or EditTexts.

Post a Comment for "Displaying Text In An Android Studio Project"