getText()。toString()没有返回任何内容

时间:2014-09-01 20:31:44

标签: android

所以我试图让我在EditText框中输入的字符串在按钮点击时显示为Toast但是没有返回任何值。怎么回事?

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



}

我已在按钮的onClick属性中声明了emailLogin方法。正在生成Toast但不包含任何内容。

修改

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>

0 个答案:

没有答案