據我所知,這將存儲用戶並傳入我所創建的變量。然後獲取文本並將其轉換爲字符串。現在如果發生這種情況,當我打電話時只有一個空白的氣泡出現?爲什麼當我有一個字符串時,吐司輸出中會出現空白文本?
package com.set.ultimax.login;
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 android.widget.Toast;
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button logIn;
EditText user;
EditText pass;
logIn = (Button) findViewById(R.id.btn);
user = (EditText) findViewById(R.id.username);
pass = (EditText) findViewById(R.id.password);
final String userValue = user.getText().toString();
final String passValue = pass.getText().toString();
logIn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Toast.makeText(Main.this,userValue, Toast.LENGTH_LONG).show();
Toast.makeText(Main.this,passValue, Toast.LENGTH_LONG).show();
}
});
}
}
請接受回答 – nandsito