I would like to add a LinearLayout above a ListView, so that when you scroll the screen, it scrolls the entire layout. In my LinearLayout, I have an AChartEngine GraphicalView, which I want above the ListView. I added a ScrollView, and inside that a Spinner, LinearLayout ListView, but when I run the app, only the ListView and the Spinner show up. The LinearLayout doesn't show up on the screen.
Here is my xml file. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Spinner
android:id="#+id/spending_report_cycle_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/spending_report_graph"
android:layout_width="wrap_content"
android:layou`enter code here`t_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal" />
<ListView
android:id="#+id/spending_report_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
When I call the method that returns my graph, I am given a View, which I need to add to the Layout. The only way I know of to do this is to add it to a LinearLayout.
graphLayout = (LinearLayout)view.getViewById(R.id.spending_report_graph);
graph = PieGraph.getNewInstance(getActivity(), items, items.size());
graphLayout.addView(graph);
Is is this you want to achieve ?
Test Image http://imageshack.com/a/img43/3327/f091.png
IF yes, then description is like, Item1 is the spinner, Item 2 on the bottom is the ListView and the black line in between is the View and the extire layout is in the linear layout and it has one child (Scroll View) and only one direct child of scroll view that's Linear layout.
Here's the xml for it. I am not sure if this is what you are looking for.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="#+id/spending_report_cycle_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="#+id/spending_report_graph"
android:layout_width="wrap_content"
android:layout_height="3dp"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:orientation="vertical" />
<ListView
android:id="#+id/spending_report_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Here's the edited answer :
Test Image http://imageshack.com/a/img809/7741/ti70.png
Here's I am using fragment just to confirm everything was working fine and yes, everything's working perfect.
as you see, there's the fragment I am using, the spinner is at the top, list view on the bottom and after executing the code, here's how the view looks like :
Test Image 2 http://imageshack.com/a/img713/685/qpbi.png
Here, the view inside two green lines is the fragment. Here's the code for everything:
First : the yourmainlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="#+id/spending_report_cycle_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="#+id/SomeView2"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:background="#008080"
android:orientation="vertical" />
<fragment
android:id="#+id/fragment_content_1"
android:name="com.mike.passintents.Fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="#+id/SomeView2"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:background="#008080"
android:orientation="vertical" />
<ListView
android:id="#+id/spending_report_listview"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:background="#333333" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
Second : The Fragment1
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mike.stackoverflowquestions.R;
public class Fragment1 extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_fragment_1, container, false);
}
}
Third: Main Activity
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import com.mike.stackoverflowquestions.R;
public class ActivityA extends Activity {
String somevalue1 = "Hello";
String somevalue2 = "World";
ListView mListView;
String[] numbers_text = new String[] { "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen" };
ArrayList<String> mArrayList;
ArrayAdapter<String> mAdapter;
ArrayAdapter<String> spinnerAdapter;
Spinner spinner1;
TextView tV;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_view_stack);
mArrayList = new ArrayList<String>();
for (String s : numbers_text) {
mArrayList.add(s);
}
spinner1 = (Spinner) findViewById(R.id.spending_report_cycle_spinner);
tV = (TextView) findViewById(R.id.tv);
mListView = (ListView) findViewById(R.id.spending_report_listview);
mAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, mArrayList);
mListView.setAdapter(mAdapter);
spinnerAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item,
mArrayList);
spinner1.setAdapter(spinnerAdapter);
}
public void selectFragment(View view) {
Fragment fr;
if (view == findViewById(R.id.btnSayHi)) {
fr = new Fragment1();
} else {
fr = new Fragment1();
}
FragmentManager fm = getFragmentManager();
FragmentTransaction mFragmentTransaction = fm.beginTransaction();
mFragmentTransaction.replace(R.id.fragment_content_1, fr);
mFragmentTransaction.commit();
}
}
I made the edit. Please let me know if this works. Good luck..:)
Related
I've created a stopwatch app when the user clicks the Lap button just gives the current time the timer is at. My problem is text in ListView displays at the left corner. I'm finding it impossible to center the text in my listview. Here I attached my XML and Java code.
activity_main.xml
<RelativeLayout 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"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="100dp"
android:text="format"
android:textSize="40dp"
android:textStyle="bold" />
<Button
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="110dp"
android:text="Start" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="#id/start"
android:text="Reset" />
<ListView
android:id="#+id/listview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/start"
android:layout_marginLeft="50dp"
android:layout_marginTop="9dp"
android:layout_marginRight="50dp"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll" />
</RelativeLayout>
MainActivity.java:
public class MainActivity extends AppCompatActivity
{
TextView time;
Button reset, start;
ListView listView;
long startTime, TimeBuff, millisecondsTime, UpdateTime = 0L;
int seconds, milliseconds, minutes;
Handler handler;
List<String> ListElementsArrayList;
ArrayAdapter<String> adapter;
String[] ListElements = new String[]{};///creating arrays of string type
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
time = (TextView) findViewById(R.id.textView);
start = (Button) findViewById(R.id.start);
reset = (Button) findViewById(R.id.reset);
listView = (ListView) findViewById(R.id.listview1);
handler = new Handler();
//Getting the list of array
ListElementsArrayList = new ArrayList<String>(Arrays.asList(ListElements));
adapter = new ArrayAdapter<String>(MainActivity.this,
android.R.layout.simple_list_item_1,
ListElementsArrayList);
listView.setAdapter(adapter);
}
}
To do it You have to create a layout in Your res/layout folder. With name e.g. list_item_layout.xml. In this layout add this:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textSize="20sp" />
In this file, You can make custom TextView which You want to display (change font, size etc.). To center text use android:gravity="center"
Next, when You create an ArrayAdapter, use this layout:
adapter = new ArrayAdapter<String>(
MainActivity.this,
R.layout.list_item_layout, // here You use created layout
ListElementsArrayList
);
Result:
I want to use a Navigation Drawer within my App by using activities instead of fragments. By using Layout inflater in the different activities I tried to keep the same navigation drawer as in the MainActivity, but to change the inner layout. My problem is that somehow the layout of the MainActivity cant be replaced. When clicking on a item in the navigation drawer the new Activtiy opens and starts the layoutinflater. But the Layout Of the Main Activity remains, while the layout of the other Activity is just added.
public class MainActivity extends AppCompatActivity implements
TabLayout.OnTabSelectedListener{
public static String TAG = "MainActivity";
DrawerLayout drawerLayout;
ActionBarDrawerToggle actionBarDrawerToggle;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "CREATED");
NavigationView navigationView = (NavigationView)
findViewById(R.id.navigation_view);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, ^
toolbar, R.string.drawer_open, R.string.drawer_closed);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
navigationView.setNavigationItemSelectedListener(new
NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.Mensa_in_der_Nähe:
Intent anIntent = new Intent(getApplicationContext(),
LocationActivity.class);
startActivity(anIntent);
drawerLayout.closeDrawers();
break;
}
return false;
}
});
Then the xml file of main activity:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusableInTouchMode="true">
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/overview_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/content_frame">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="enterAlways|scroll"
app:popupTheme="#style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="#+id/menu_tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabMode="fixed" />
<android.support.design.widget.TabLayout
android:id="#+id/canteen_tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabMode="scrollable" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/dish_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</android.support.v4.view.ViewPager>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?attr/actionBarSize"
android:background="#android:color/white"
app:menu="#menu/drawer_menu" />
the other activity:
public class LocationActivity extends MainActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout contentFrameLayout = (FrameLayout)
findViewById(R.id.content_frame);
getLayoutInflater().inflate(R.layout.activity_location,
contentFrameLayout);
}}
And the xml file of the other activity:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TimePicker
android:id="#+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
I have a question regarding android layouts. I cannot achieve what I am looking for and I need some direction.
I am looking for a layout that will be inside a Scroll View layout. its hard to explain but a picture is worth thousand words.enter image description here
I want this inside a scroll view, can any help please?
If you do not want to add images dynamically than this is the layout you want Try this.
activity_main.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linMain"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<RelativeLayout
android:id="#+id/lin1"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_margin="10dp">
<ImageView
android:id="#+id/imgView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#android:color/holo_purple" />
<ImageView
android:id="#+id/imgView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#id/imgView1"
android:layout_marginTop="20dp"
android:background="#android:color/holo_red_light" />
<ImageView
android:id="#+id/imgView3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#id/imgView2"
android:layout_marginTop="20dp"
android:background="#android:color/holo_green_light" />
<ImageView
android:id="#+id/imgView4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="#id/imgView3"
android:layout_marginTop="20dp"
android:background="#android:color/holo_blue_light" />
</RelativeLayout>
<LinearLayout
android:id="#+id/lin2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/linImages"></WebView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Here i am attaching screenshot of this layout UI.
Try this,I have made two layouts ..
1) activity_main that contains gridview and webview.
2)activity_gridview which contains imageview which will inflate in gridview.
I have added images dynamically to Gridview using BaseAdapter.
In MainActivity i have set that Adapter to GridView. Try this code once.
activity_main.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linImages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/grid"
android:layout_width="100dp"
android:layout_height="match_parent"
android:numColumns="1"></GridView>
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/linImages"></WebView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
activity_gridview.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imgView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/star2" />
<ImageView
android:id="#+id/imgView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/star1" />
<ImageView
android:id="#+id/imgView3"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/star3" />
<ImageView
android:id="#+id/imgView4"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#drawable/star1" />
</LinearLayout>
CustomAdapter.java :
public class CustomAdapter extends BaseAdapter {
Context context;
int flags[];
LayoutInflater inflter;
public CustomAdapter(Context applicationContext, int[] flags) {
this.context = applicationContext;
this.flags = flags;
inflter = (LayoutInflater.from(applicationContext));
}
#Override
public int getCount() {
return flags.length;
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflter.inflate(R.layout.activity_gridview, null);
ImageView imgView1 = (ImageView) view.findViewById(R.id.imgView1);
ImageView imgView2 = (ImageView) view.findViewById(R.id.imgView2);
ImageView imgView3 = (ImageView) view.findViewById(R.id.imgView3);
ImageView imgView4 = (ImageView) view.findViewById(R.id.imgView4);
imgView1.setImageResource(flags[0]);
imgView2.setImageResource(flags[1]);
imgView3.setImageResource(flags[2]);
imgView4.setImageResource(flags[3]);
return view;
}
}
MainActivity.java :
public class MainActivity extends AppCompatActivity {
int images[] = {R.drawable.star2, R.drawable.star1, R.drawable.star3, R.drawable.star1};
GridView grid;
CustomAdapter customAdapter;
WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView= (WebView) findViewById(R.id.webView);
grid = (GridView) findViewById(R.id.grid);
customAdapter = new CustomAdapter(getApplicationContext(), images);
grid.setAdapter(customAdapter);
}
}
I want to add to my application ScreenView, but i'm only getting error.
My layout:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/bg"
android:id="#+id/mainlayout"
tools:context=".NwActivity" android:baselineAligned="false">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/rlA" >
<TextView
android:id="#+id/teamA"
android:text="#string/teamA"
android:textSize="24sp"
style="#style/Txt" />
<Button
android:id="#+id/pAddA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/teamA"
style="#style/Txt"
android:text="#string/pAdd"
android:onClick="addA" />
<EditText
android:id="#+id/eta0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/pAddA"
style="#style/Txt"
android:hint="#string/pHint" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/rlB" >
<TextView
android:id="#+id/teamB"
android:text="#string/teamB"
android:textSize="24sp"
style="#style/Txt" />
<Button
android:id="#+id/pAddB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/teamB"
style="#style/Txt"
android:text="#string/pAdd"
android:onClick="addB" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
Activity:
package some.program;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.RelativeLayout;
public class NwActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nw);
}
public int skid = 0;
public void addA(View view) {
if(skid < 14) {
skid = skid + 1;
//LinearLayout ll = (LinearLayout) findViewById(R.id.mainlayout);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.rlA);
EditText et1 = new EditText(this);
et1.setHint(R.string.pHint);
String strID = "eta" + skid;
int nid = getResources().getIdentifier(strID, "id", this.getPackageName());
et1.setId(nid);
int oskid = skid - 1;
int oid;
String resID = "eta" + oskid;
oid = getResources().getIdentifier(resID, "id", this.getPackageName());
RelativeLayout.LayoutParams params1= new RelativeLayout.LayoutParams
( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.BELOW, oid);
params1.addRule(RelativeLayout.CENTER_HORIZONTAL);
et1.setLayoutParams(params1);
et1.setTextAppearance(this, R.style.Txt);
rl.addView(et1);
}
}
public void addB(View view) {
}
}
How can i add ScrollView, that will not make mess on my layout? When clicking Button, app is creating EditText forms. Everything works fine, but all EditText fields don't fit on layout and don't appear.
There may be some other issues in your layout, some of the issues which I have found are
Firstly ScrollView only takes one direct child, while you are declaring two views rlA and rlB in ScrollView. (You can make it working by putting ScrollView as your main layout and putting LinearLayout in place of ScrollView)
Secondly you should add layout_width and layout_height attributes for your layouts (I guess you are already declaring in your STYLES).
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 to android:orientation="vertical".
EDIT: Here is the reference in the Android docs:
http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:orientation