Okay, so I decided to take the Google classes for learning droid devving. I decided instead of the simple input box and button I would make multiple ones, and have each display a set color. The issue is it is jamming all input boxes on one line, rather than their own separate lines. This is what I have in the activity_color.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="@+id/edit_message_blue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message_blue" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send_blue"
android:onClick="sendMessageBlue" />
<EditText android:id="@+id/edit_message_orange"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message_orange" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send_orange"
android:onClick="sendMessageOrange" />
</LinearLayout>
This is the main java class
package com.example.color.texts;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class ColorTexts extends Activity {
public final static String EXTRA_MESSAGE = "com.example.colortexts.MESSAGE";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color_texts);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_color_texts, menu);
return true;
}
/** Called when the user clicks the Send button for Blue */
public void sendMessageBlue(View view) {
Intent intent = new Intent (this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message_blue);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
/** Called when the user clicks the Send button for Red */
public void sendMessageRed(View view) {
Intent intent = new Intent (this, DisplayMessageActivityRed.class);
EditText editText = (EditText) findViewById(R.id.edit_message_red);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
/** Called when the user clicks the Send button for Orange */
public void sendMessageOrange(View view) {
Intent intent = new Intent (this, DisplayMessageActivityOrange.class);
EditText editText = (EditText) findViewById(R.id.edit_message_orange);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
Now I guess the question is how to either tell it to start a new line, like android:layout_next=”1″ or something (I KNOW THAT DOESN’T EXIST), or would I have to add to the public class? Such as make another layout file and reference to that? I highly doubt the latter would work.
EDIT: Per the instructions laid out, I think this is how I was supposed to do it, but it only know shows the first line 🙁
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText android:id="@+id/edit_message_blue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message_blue" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send_blue"
android:onClick="sendMessageBlue" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="@+id/edit_message_red"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message_red" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send_red"
android:onClick="sendMessageRed" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="@+id/edit_message_orange"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message_orange" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send_orange"
android:onClick="sendMessageOrange" />
</LinearLayout>
</LinearLayout>
Your parent layout is set to be
android:orientation="horizontal". This needs to be set toandroid:orientation="vertical".EDIT: Here is the reference in the Android docs:
http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:orientation