gpt4 book ai didi

android - 想 toast 的用户名,但是当我尝试登录时却给了我很大的压力

转载 作者:行者123 更新时间:2023-12-03 17:44:34 26 4
gpt4 key购买 nike

使用登录后,我想吐出用户名。
但是,当我尝试单击登录按钮时,
它给了我力量。
我看着logcat,但是什么也没显示。

这种编码是在说。
它将根据我在登录屏幕中输入的名称来烘烤用户名。
不会有任何密码。

我不知道我的代码有什么问题。
有人可以帮我吗?

homeactvity.java:

public class homeActivity extends Activity{
Button btnLogIn;
Button btnAbout;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.homescreen);
// create a instance of SQLite Database

// Get The Reference Of Buttons
btnLogIn=(Button)findViewById(R.id.buttonLogIn);

btnAbout=(Button)findViewById(R.id.buttonAbout);

// Set OnClick Listener on SignUp button

// set OnClick Listener on About button
btnAbout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub

/// Create Intent for About and start activity
Intent intentAbout=new Intent(getApplicationContext(),about.class);
startActivity(intentAbout);
}
});


}
// Methods to handleClick Event of Sign In Button
public void LogIn(View V)
{
final Dialog dialog = new Dialog(homeActivity.this);
dialog.setContentView(R.layout.login);
dialog.setTitle("Login");

// get the Refferences of views
final EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);

Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogIn);

// Set On ClickListener
btnLogIn.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// get The User name and Password
String userName=editTextUserName.getText().toString();

// fetch the Password form database for respective user name
// check if the Stored password matches with Password entered by user
if(userName.equals(userName))
{
Toast.makeText(homeActivity.this, "Welcome," + userName, Toast.LENGTH_LONG).show();
dialog.dismiss();
Intent mainact=new Intent(getApplicationContext(),MainActivity.class);
startActivity(mainact);


}
else
{
Toast.makeText(homeActivity.this, "No Such Username", Toast.LENGTH_LONG).show();
}
}
});

dialog.show();

}

@Override
protected void onDestroy() {
super.onDestroy();
// Close The Database
}

}

homescreen.xml:
<LinearLayout 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:orientation="vertical"

android:gravity="center_vertical"
>


<Button
android:id="@+id/buttonLogIn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Login"
android:onClick="LogIn"/>

<Button
android:id="@+id/buttonAbout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="About" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/home" />

</LinearLayout>

login.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:orientation="vertical" >

<EditText
android:id="@+id/editTextUserNameToLogin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User Name"
android:ems="10" >
<requestFocus />
</EditText>


<Button
android:id="@+id/buttonLogin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Log In" />
</LinearLayout>

最佳答案

你必须用

Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogin);

代替
Button btnLogIn=(Button)dialog.findViewById(R.id.buttonLogIn);

LogIn方法中,因为 Button中的 login.xml包含id buttonLogin而不是 buttonLogIn

关于android - 想 toast 的用户名,但是当我尝试登录时却给了我很大的压力,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21250892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com