2013-02-05 23 views
-2

我在將字符串中的可編輯文本值存儲時遇到問題。我只是想存儲一個用戶輸入存儲在某個變量中的值。我在存儲一個值之後使用toast來檢查值是否存儲在其中,並且烤麪包沒有顯示任何值。我嘗試下面的代碼,但沒有發現它有幫助。不存儲字符串中的EditText vlaue

package com.example.electropollsys; 

import android.annotation.SuppressLint; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.Window; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 



public class CreateAcc extends Activity { 
    protected void onCreate(Bundle savedInstanceState){ 
     super.onCreate(savedInstanceState); 


    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setContentView(R.layout.create_acc); 

    final Button b = (Button) findViewById(R.id.button3); 
    b.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 

      Intent i = new Intent(CreateAcc.this, SignIn.class); 
      i.addFlags(
       Intent.FLAG_ACTIVITY_CLEAR_TOP | 
       Intent.FLAG_ACTIVITY_NEW_TASK); 
       startActivity(i); 
     } 


    }); 

    final Button a = (Button) findViewById(R.id.button1); 
    a.setOnClickListener(new View.OnClickListener() { 


      @SuppressLint("ShowToast") 
      public void onClick(View v){ 

       EditText input1= (EditText)findViewById(R.id.fname1); 
       String fname = input1.getEditableText().toString(); 

       EditText input2= (EditText) findViewById(R.id.lname1); 
       String lname = input2.getEditableText().toString(); 

       Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG); 
       Toast.makeText(CreateAcc.this,"...."+lname+"...." , Toast.LENGTH_LONG); 

       } 
     }); 
    } 
    } 
+1

你應該有你的編輯以前equestion ...而不是發佈新 – Pragnani

+1

加秀()在吐司消息 – Pragnani

+0

結束時,我不知道y爲這沒有編輯那裏..所以,你發佈了一個新的問題.. –

回答

3

嘗試:

Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG).show(); 
Toast.makeText(CreateAcc.this,"...."+lname+"...." , Toast.LENGTH_LONG).show(); 

敬酒不顯示,除非show()方法被調用。 makeText()方法返回Toast對象,您必須使用它來顯示Toast。

您通常會對此發出警告,但您似乎已用@SuppressLint("ShowToast")將其壓制。

+0

現在非常感謝你的工作! –

+1

@ user2044144請點擊勾號將其標記爲解決方案,然後 –

0

你確實喜歡。

Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG); 

使用此函數啓動吐司對象並返回對象,但顯示吐司通知您需要調用該對象的show方法。

而不是寫這個。

Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG).show(); 

OR

Toast toast = Toast.makeText(CreateAcc.this,"...."+fname+"...." , Toast.LENGTH_LONG); 
toast.show();