I tried to display User Input from my main activity to my second activity, but when I typed in and click the send button on the main activity the whole app just crashes. Please help!
crash solved! Thanks a lot!
However, I can't get the message to display on the second activity.
MainActivity.java
package com.example.dell_inspiron.sendmessage;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import static android.R.id.message;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String message = getResources().getString(R.string.UserInput);
final Button send = (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Intent sendMessage = new Intent(MainActivity.this, DisplayMessageActivity.class);
sendMessage.putExtra("UserInput", message);
startActivity(sendMessage);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
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"
tools:context="com.example.dell_inspiron.sendmessage.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="#string/edit"
android:ems="10"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="15dp"
android:id="#+id/UserInput" />
<Button
android:text="#string/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/UserInput"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="14dp"
android:id="#+id/send"
android:onClick="sendMessage" />
<TextView
android:text="#string/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
DisplayMessageActivity.java
package com.example.dell_inspiron.sendmessage;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class DisplayMessageActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Intent Extra = getIntent();
String textView = Extra.getStringExtra("UserInput");
TextView UserInput = (TextView) findViewById(R.id.UserOutput);
UserInput.setText(textView);
final Button button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
launchActivity();
}
});
}
private void launchActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
activity_display_message.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_display_message"
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"
tools:context="com.example.dell_inspiron.sendmessage.DisplayMessageActivity">
<Button
android:text="#string/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="51dp"
android:id="#+id/button2" />
<TextView
android:text="#string/UserOutput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:id="#+id/UserOutput" />
<TextView
android:text="#string/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/enter"
android:textSize="18sp"
android:textColor="#android:color/holo_purple" />
</RelativeLayout>
You are passing int, but receive it in String, so your app crashed.
MainActivity
int message = R.string.UserInput;
Intent sendMessage = new Intent(MainActivity.this, DisplayMessageActivity.class);
sendMessage.putExtra("UserInput", message);
DisplayMessageActivity
Bundle Extra = getIntent().getExtras();
String textView = Extra.getString("UserInput");
You should also add
intent.putExtra("UserInput", message);
into launchActivity method.
Solution 1
Change String textView = Extra.getString("UserInput"); to int textView= Extra.getIntExtra("UserInput", 0);
Solution 2
To send the message to your second Activity, you need to use intent inside your MainActivity button click. Modify your code as below.
package com.example.dell_inspiron.sendmessage;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import static android.R.id.message;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String message = getResources().getString(R.string.UserInput);
final Button send = (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Intent sendMessage = new Intent(MainActivity.this,DisplayMessageActivity.class);
sendMessage.putExtra("UserInput", message);
startActivity(sendMessage);
}
});
}
}
Solution 3
This line look wrong to me
final String message = getResources().getString(R.string.UserInput);
If you want to get the editText string, this is the way to go
EditText input = (EditText)findViewById(R.id.UserInput); // declare your editText
final String message = input.getText().toString(); // get your input type
You mentioned that you are getting the user input from the MainActivity but i don't see anything like that in your code but you can do the below to pass some value from one activity to another...
Change your second activity like this
Bundle Extra = getIntent().getExtras();
String textView = Extra.getString("UserInput");
to
Intent Extra = getIntent();
String textView = Extra.getStringExtra("UserInput");
and change your MainActivity like this
int message = R.string.UserInput;
to
String message= getResources().getString(R.string.UserInput);
and
final Button send = (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
launchActivity();
}
});
to
Button send = (Button) findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
startActivity(sendMessage);
}
});
There is issue with your second Activity.You are passing int value in Intents but trying to get String value.
Change it as below:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class DisplayMessageActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Bundle Extra = getIntent().getExtras();
int textView = Extra.getInt("UserInput");
TextView UserInput = (TextView) findViewById(R.id.UserInput2);
UserInput.setText(textView);
final Button button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
launchActivity();
}
});
}
private void launchActivity() {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
Related
This is my java class, MainActivity.java.
Basically I'm trying to create a button performing addition on variable i. Everything seems to be correct as far as I learnt until now. I am getting an error message on my emulator saying:
unfortunately myfirstandroidapp stopped working.
Code:
package com.example.android.myfirstandroidapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
int i = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button button = (Button) findViewById(R.id.addButton);
final TextView txtView = (TextView) findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i++;
txtView.setText("i value is:"+i);
}
});
setContentView(R.layout.activity_main);
}
}
This is my layout.xml
main_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
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"
tools:context="com.example.android.myfirstandroidapp.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your value is:0"
android:id="#+id/textView"
android:textColor="#android:color/black"
android:textStyle="normal|bold"
android:textSize="14dp" />
<Button
android:text="Add One"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_marginTop="25dp"
android:id="#+id/addButton"
android:background="#android:color/holo_green_dark"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
You need to call setContentView() before initializing any View.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.addButton);
final TextView txtView = (TextView) findViewById(R.id.textView);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i++;
txtView.setText("i value is:"+i);
}
});
}
I'm trying to call an EditText from one activity to another but when i do my app crashes.
I've tried using the addPreferencesFromResource method using 'import android.preference.PreferenceActivity' and import android.preference.PreferenceFragment' but the 'addPreferencesFromResource' stays red.
How can I make it callable ?
settings_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:id="#+id/linearLayout">
<TextView
android:layout_width="127dp"
android:layout_height="wrap_content"
android:text="website A"
android:id="#+id/textView3"
android:layout_weight="0.07"
android:layout_marginTop="115dp"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"
android:onClick="showZaire"
android:id="#+id/button5"
android:layout_gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/textView3"
android:layout_toEndOf="#+id/textView3" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/webA"
android:layout_alignBottom="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:layout_toEndOf="#+id/textView3" />
<TextView
android:layout_width="127dp"
android:layout_height="wrap_content"
android:text="website B"
android:id="#+id/textView2"
android:layout_weight="0.07"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="34dp" />
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="#+id/webB"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView2"
android:layout_toEndOf="#+id/textView2" />
</LinearLayout
Second Activity
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class secondActivity extends Activity {
EditText webs = (EditText)findViewById(R.id.webA);// this is what im trying to call from settings
String web = webs.getText().toString();
TextView titleText;
String title = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seccond_layout);
Button button = (Button) findViewById(R.id.refresh);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
restartActivity(seccondActivity.this);
}
});
//initialize variables
titleText = (TextView) findViewById(R.id.titleText);
;
//run on new thread because we cannot do network operation on main thread
new Thread(new Runnable() {
#Override
public void run() {
try {
//get the Document object from the site. Enter the link of site you want to fetch
Document document = Jsoup.connect(web).get(); // this is the website string
//Get the title of blog using title tag
title = document.select("h6").text().toString();
//set the title of text view
//Run this on ui thread because another thread cannot touch the views of main thread
runOnUiThread(new Runnable() {
#Override
public void run() {
//set both the text views
titleText.setText(title);
titleText.setMovementMethod(new ScrollingMovementMethod());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
public void showZaire(View view) {
String button_test;
button_test = ((Button) view).getText().toString();
if (button_test.equals("Home")) {
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
} else if (button_test.equals("Directions")) {
Intent intent = new Intent(this, ThirdActivity.class);
startActivity(intent);
}
}
}
settingsActivity
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.text.Editable;
import android.text.Layout;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
* Created by Shane on 10/01/2016.
*/
public class SettingsActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_layout);}
public void showZaire(View view) {
String button_test;
button_test = ((Button) view).getText().toString();
if (button_test.equals("Back")) {
Intent intent1 = new Intent(this, MainActivity.class);
startActivity(intent1);
} else if (button_test.equals("Help")) {
Intent intent2 = new Intent(this, Help.class);
startActivity(intent2);
}
}
}
It's a simple login activity but when it must switch activity, the app crash.
I tried use also the normal form pubic void onClick() {...} but it doesn't work.
Login.java
package com.example.corrado_mattia_danny.face_offbrains;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.Toast;
public class Login extends Activity {
private Player player;
private Button login;
private EditText Username;
private EditText Password;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
login=(Button)findViewById(R.id.button_sign_in);
Username=(EditText)findViewById(R.id.nickname);
Password=(EditText)findViewById(R.id.password);
String a = Username.getText().toString();
String b = Password.getText().toString();
player.inserisciCredenziali(a,b); //insert into a player class
//username and password
signIn();
}
public void signIn() {
Intent intent = new Intent(this, Home.class);
startActivity(intent);
}
}
activity_login.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"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.corrado_mattia_danny.face_offbrains.Login"
android:background="#drawable/sfondo_custom" >
<EditText
android:layout_width="wrap_content"
android:layout_height="35dp"
android:inputType="textPersonName"
android:hint="Nickname"
android:ems="10"
android:id="#+id/nickname"
android:linksClickable="false"
android:textColor="#ff000000"
android:background="#ffd4d4d4"
android:textStyle="normal|bold|italic"
android:layout_marginTop="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="35dp"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:layout_below="#+id/nickname"
android:layout_alignStart="#+id/nickname"
android:layout_marginTop="30dp"
android:hint="password"
android:textColor="#ff000000"
android:background="#ffd4d4d4"
android:textStyle="normal|bold|italic" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/button_sign_in"
android:background="#ffffeb00"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/nickname"
android:layout_marginLeft="10dp"
android:onClick="signIn"/>
</RelativeLayout>
Home.java
the buttons in Home doesn't work yet.
package com.example.corrado_mattia_danny.face_offbrains;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class Home extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Intent intent = getIntent();
Button bottone_sfida_amico = (Button)findViewById(R.id.button_sfida_amico);
Button bottone_avversario_casuale = (Button)findViewById(R.id.button_avversario_casuale);
}
}
}
When you set a method through the android:onClick attribute, your method signIn() must have a parameter View, which is the source of the event. So, declare the method as follows:
public void signIn(View view) {
...
}
can be 2 things:
1did you declare it on the manifest?
<activity android:name=".SampleActivity" android:screenOrientation="landscape"
android:label="SampleActivity"
/>
and the other reason must be the declaration of your function, when you call it for the layout it should be like this (View v) as param
public void signIn(View v) {
Intent intent = new Intent(this, Home.class);
startActivity(intent);
}
I would like to create checkbox with text that would behave something like what i have below in pseudo code:
Set in text in EditText field
if Button clicked:
create new Checkbox with entered text.
How do i go about doing that in Android?
So far ive got the button :) ... but dont know how to get new Checkbox with text in it ,if its clicked
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
Button create = (Button) findViewById(R.id.button1);
create.setOnClickListener(this);
EditText textInCheckBox = (EditText) findViewById(R.id.editText1);
}
#Override
public void onClick(View v) {
// TODO Automatisch generierter Methodenstub
switch (v.getId()) {
case R.id.button1:
//after creating new checkbox with text in it
//Editbox should restet text field to null;
break;
}
}
}
Here is some code that will demonstrate how to add checkboxes dynamically with the title you entered into the EditText.
MainActivity.java
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText txtTitle = (EditText) findViewById(R.id.txtTitle);
final Button btnCreate = (Button) findViewById(R.id.btnCreate);
final RadioGroup radContainer = (RadioGroup) findViewById(R.id.radContainer);
final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
btnCreate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String name = txtTitle.getText().toString().trim();
if (!name.isEmpty()) {
CheckBox checkBox = new CheckBox(MainActivity.this);
checkBox.setText(name);
checkBox.setLayoutParams(params);
radContainer.addView(checkBox);
} else {
Toast.makeText(MainActivity.this, "Enter a title for the checkbox", Toast.LENGTH_SHORT).show();
}
}
});
}
}
activity_main.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:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp" >
<EditText
android:id="#+id/txtTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
<Button
android:id="#+id/btnCreate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Checkbox" />
<RadioGroup
android:id="#+id/radContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I have two activities and the first is generating properly however the second is not. only the first element in the xml file will show up. here is my xml file:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/alternateActivity"
android:shadowColor="#color/shadowColor"></TextView>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/oldActivityButton"
android:text="#string/oldActivityButton"></Button>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/changeText"
android:text="#string/changeTextButton"></Button>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/originalText"
android:id="#+id/textToChange"></TextView>
</LinearLayout>
and here is my activity that corresponds:
package fsg.dev.activitytest;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class newActivity extends Activity {
private Button oldActivityButton;
private Button changeText;
private TextView textToChange;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alternate);
oldActivityButton = (Button) findViewById(R.id.oldActivityButton);
changeText = (Button) findViewById(R.id.changeText);
textToChange = (TextView) findViewById(R.id.textToChange);
oldActivityButton.setOnClickListener(new OnClickListener(){
public void onClick(View view){
changeActivity();
}
});
changeText.setOnClickListener(new OnClickListener(){
public void onClick(View view){
changeText();
}
});
}
private void changeActivity(){
Intent i = new Intent(this, activityTest.class);
startActivity(i);
}
private void changeText(){
if(textToChange.equals(R.string.originalText)){
textToChange.setText(R.string.newText);
} else {
textToChange.setText(R.string.originalText);
}
}
}
has anyone else seen this problem? or know of a way to fix it?
Try to add android:orientation="vertical" to your LinearLayout
replace
Intent i = new Intent(this, activityTest.class);
by
Intent i = new Intent().setClass(this, activityTest.class);