我是Android的新手,我正在制作一个应用程序,其中我需要显示带有2个按钮的电子邮件编辑文本字段,当我单击“忘记密码”按钮时,提交和取消该按钮,它应该显示在其下方。任何人都可以通过xml布局信息和java来帮助我。感谢您的帮助,并在此先感谢。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/LoginLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="21dp"
android:background="@drawable/rounders_fpass"
android:ems="10"
android:hint="PASSWORD"
android:inputType="textPassword"
android:paddingLeft="10dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:background="@drawable/rounders_email"
android:ems="10"
android:hint="EMAIL ID"
android:inputType="textEmailAddress"
android:paddingLeft="10dp" />
<Button
android:id="@+id/button_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/editText2"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="LOGIN" />
<Button
android:id="@+id/fp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Forgot Password?" />
<TextView
android:id="@+id/appear"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@+id/fp"
android:layout_centerHorizontal="true"
android:layout_marginTop="36dp"
android:text="APPEAR" />
</RelativeLayout>
</RelativeLayout>
JAVA:
public class Login extends Activity {
Button log, fp;
TextView forgot;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
// views
views();
// clicklistener
setClickListenerOnButton_log();
setClickListenerOnButton_fp();
}
private void setClickListenerOnButton_fp() {
// TODO Auto-generated method stub
fp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
setContentView(forgot);
forgot.setVisibility(View.VISIBLE);
}
});
}
private void views() {
// TODO Auto-generated method stub
log = (Button) findViewById(R.id.button_login);
fp = (Button) findViewById(R.id.fp);
forgot = (TextView) findViewById(R.id.appear);
}
private void setClickListenerOnButton_log() {
// TODO Auto-generated method stub
log.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Login.this, MainActivity.class));
}
});
}
}
试试这个
Just Remove
"setContentView(forgot);" Line
from your setClickListenerOnButton_fp().
并运行您的应用程序。您的应用程序不会崩溃。
尝试让我知道,这可以解决您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句