App crash using intent to switch activity - android

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);
}

Related

"Unfortunately, ROC has stopped." When code to retrive data from firebase(Login). NoActionBar Solution also not working

When I jump from MainActivity to AdminLog it works when adminLog.java contains the code as shown below. I have also searched for solution Like enabling noAction bar but it also doen't work. Not only for login code but it is shows same issue when I try to retrieve data from my firebase database.
package com.example.roc;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class adminLog extends AppCompatActivity {
EditText txtEmail, txtPassword;
ProgressBar progressBar;
Button btnSignin;
private FirebaseAuth mAuth;
private Button mgo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_log);
mgo=(Button)findViewById(R.id.adminLoginBtn);
mgo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(adminLog.this,adminWorking.class));
}
});
}
}
But it stops Working when I add login code in adminLog.java file which is also shown below.
package com.example.roc;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
public class adminLog extends AppCompatActivity {
EditText txtEmail, txtPassword;
ProgressBar progressBar;
Button btnSignin;
private FirebaseAuth mAuth;
private Button mgo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin_log);
mAuth = FirebaseAuth.getInstance();
initializeUI();
btnSignin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
loginUserAccount();
}
});
}
private void loginUserAccount() {
progressBar.setVisibility(View.VISIBLE);
String email, password;
email = txtEmail.getText().toString();
password = txtPassword.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(getApplicationContext(), "Please enter email...", Toast.LENGTH_LONG).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(getApplicationContext(), "Please enter password!", Toast.LENGTH_LONG).show();
return;
}
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Login successful!", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
Intent intent = new Intent(adminLog.this, adminWorking.class);
startActivity(intent);
}
else {
Toast.makeText(getApplicationContext(), "Login failed! Please try again later", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
private void initializeUI() {
txtEmail= findViewById(R.id.adminETxt);
txtPassword = findViewById(R.id.adminPTxt);
btnSignin = findViewById(R.id.adminLoginBtn);
progressBar = findViewById(R.id.progressBar);
}
}
adminlog.xml file code is also given below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".adminLog">
<Button
android:id="#+id/adminLoginBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="132dp"
android:text="Login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/adminPTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/customerLoginBtn"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="96dp"
android:hint="Enter your password"
app:layout_constraintBottom_toTopOf="#+id/adminLoginBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/adminETxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="332dp"
android:hint="Entere Your E-Mail"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="133dp"
android:layout_height="119dp"
android:layout_marginStart="139dp"
android:layout_marginLeft="139dp"
android:layout_marginTop="164dp"
android:layout_marginEnd="139dp"
android:layout_marginRight="139dp"
android:layout_marginBottom="448dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
What should I do to get rid of this problem.

Integrating Tap Research sdk on Android

I integrated Tap Research sdk on my Android app, but application getting force stop.
Any idea why this might be happening?
This is my code tapresearchactivity.java
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.tapr.sdk.TapResearch;
import com.tapr.sdk.TapResearchOnRewardListener;
class MyApp extends Application {
final private String YOUR_API_TOKEN = "fa7dbeeacebe7ae3e0b24e8dccaa6acb";
public class onCreate{} {
super.onCreate();
TapResearch.configure(YOUR_API_TOKEN, this);
}
}
public class TapresearchActivity extends Activity {
private Button show_button;
#Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_tapresearch);
/** Set up button to show an ad when clicked */
show_button = (Button) findViewById(R.id.showbutton);
if (TapResearch.getInstance().isSurveyAvailable()) {
show_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
TapResearch.getInstance().showSurvey();
}
});
}
}
}
And this is my xml layout file here activity_tapreserch.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=".TapresearchActivity">
<Button
android:layout_width="298dp"
android:layout_height="68dp"
android:enabled="false"
android:id="#+id/showbutton"
android:background="#drawable/button_blue"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:layout_centerHorizontal="true"/>
</RelativeLayout>

Display User Input from one activity to another in a textView

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);
}
}

Make EditText callable across Activitys

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);
}
}
}

getText().toString() not returning anything

So i am trying to get the string that i type in the EditText box appear as a Toast on button click however no value is being returned. Whats going wrong?
LoginActivity:
package com.example.yipeedo;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.format.Time;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
public class LoginActivity extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
int monthDay,month;
Time time=new Time();
private static String APP_ID="xxxx"; //for facebook
private static final int RC_SIGN_IN = 0;
private GoogleApiClient mGoogleApiClient;
private boolean mIntentInProgress;
private boolean mSignInClicked;
private ConnectionResult mConnectionResult;
private Button btnSignIn;
private Button btnSignOut, btnRevokeAccess;
EditText email;
Button login;
Button facebookButton;
private FacebookFragment facebookFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Typeface font = Typeface.createFromAsset(this.getAssets(),"fonts/RobotoCondensed-Bold.ttf");
login=(Button)findViewById(R.id.login);
login.setText("Login");
login.setTypeface(font);
if(savedInstanceState==null)
{
facebookFragment=new FacebookFragment();
Log.e("Facebook 1","Here");
getSupportFragmentManager().beginTransaction().add(android.R.id.content,facebookFragment).commit();
}
else
{
facebookFragment=(FacebookFragment)getSupportFragmentManager().findFragmentById(android.R.id.content);
}
btnSignIn = (Button) findViewById(R.id.sign_in_button);
//btnSignOut = (Button) findViewById(R.id.btn_sign_out);
//btnRevokeAccess = (Button) findViewById(R.id.btn_revoke_access);
mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();
//email=(EditText)findViewById(R.id.email_id);
}
.
.
.
.
public void emailLogin(View v)
{
//LoginParser p;
try
{
email=(EditText)findViewById(R.id.email_id);
String email_string1=email.getText().toString();
Log.e("Email is",email_string1);
String email_string="http://www.yipeedo.com/api/login.json?email_id="+email_string1;
Toast.makeText(LoginActivity.this,email_string1,Toast.LENGTH_SHORT).show();
//if(email_string.isEmpty()==true)
//{
// Toast.makeText(LoginActivity.this,"Please Enter Email Id",Toast.LENGTH_SHORT).show();
//}
//else
//{
//String email_string=email.getText().toString();
//p.email_Login(email_string,LoginActivity.this);
//new LoginParser(LoginActivity.this,email_string).execute();
//}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void googleLogin(View v)
{
Log.e("Google Button","Button Click Recognised");
signInWithGplus();
}
}
I have declared emailLogin method in the onClick attribute for the button. The Toast is being generated but contains nothing.
Edit:
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:background="#color/White"
android:orientation="vertical" >
<!--com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="220dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true">
</com.google.android.gms.common.SignInButton-->
<Button
android:id="#+id/sign_in_button"
android:layout_width="220dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Google Sign In"
android:onClick="googleLogin"
/>
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/sign_in_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp" />
<EditText
android:id="#+id/email_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sign_in_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="38dp"
android:ems="10"
android:hint="#string/email_hint"
android:inputType="textEmailAddress"
android:textColor="#color/Black"
android:width="210dp" >
</EditText>
<Button
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/sign_in_button"
android:layout_below="#+id/email_id"
android:layout_marginTop="38dp"
android:text="#string/login"
android:width="210dp"
android:background="#drawable/plan_border"
android:onClick="emailLogin"/>
</RelativeLayout>

Categories

Resources