无法将android.widget.TextView转换为android.widget.EditView
当我试图运行此代码时,它显示错误。问题是什么。如果你找到了,请告诉我。 但我并没有将Textview强制转换为EditText,但它显示了错误 我的xml文件:无法将android.widget.TextView转换为android.widget.EditView,android,android-edittext,textview,Android,Android Edittext,Textview,当我试图运行此代码时,它显示错误。问题是什么。如果你找到了,请告诉我。 但我并没有将Textview强制转换为EditText,但它显示了错误 我的xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:
<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.dailyexpenses.LoginTypeConfirmation" >
<TextView
android:id="@+id/Confirmation_password_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Confirmation_password"
android:layout_alignParentTop="true"
android:layout_marginTop="38dp"
android:text="@string/loginType_confirm" />
<EditText
android:id="@+id/Confirmation_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Confirmation_password_info"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:ems="10"
android:hint="@string/confirm_password"
android:inputType="textPassword" />
<Button
android:id="@+id/Confirmation_password_submit"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_alignLeft="@+id/Confirmation_password"
android:layout_below="@+id/Confirmation_password"
android:layout_marginTop="34dp"
android:background="@color/project_theme"
android:text="@string/submit"
android:textColor="@color/font_color" />
checkLoginType();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login_type_confirmation, menu);
return true;
}
public void checkLoginType()
{
Cursor c = db.rawQuery("select login_type password, pin_password from user_information", null);
while(c.moveToNext())
{
login_type = c.getString(0);
password = c.getString(1);
pin_password = c.getString(2);
}
if (login_type.equals("pin_password"))
{
info.setText("Enter your old pin");
old_password.setText("Confirm Pin");
old_password.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
}
}
public void validatePassword(View view)
{
if (old_password.getText().toString().equals(password))
{
Intent loginType = new Intent(this, LoginType.class);
startActivity(loginType);
}
else
{
Toast.makeText(this, "Incorrect Password", Toast.LENGTH_SHORT).show();
}
}
}
如果我删除checkLoginType()方法,它会正常工作。
提前感谢。您需要将视图传递给checkLoginType()方法,其代码如下所示:
public void checkLoginType(View v)
{
Cursor c = db.rawQuery("select login_type password, pin_password from user_information", null);
while(c.moveToNext())
{
login_type = c.getString(0);
password = c.getString(1);
pin_password = c.getString(2);
}
if(login_type.equals("pin_password"))
{
info.setText("Enter your old pin");
old_password.setText("Confirm Pin");
old_password.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
}
}
如果您仍然面临问题,请告诉我…只需将
public void checkLoginType()
更改为public void checkLoginType(视图v)
清理项目一次,然后再次运行。即使我清理并运行了您尝试的哪个api?android:onClick仅适用于api级别4以后的版本,因此如果您试图将目标设置为<1.6,那么您就不能使用它了,您需要在代码中使用setOnClickListener。对于我来说,checkLoginType()方法存在问题为什么我要将视图作为参数传递,我在onCreate()中调用了checkLoginType();告诉我问题是什么,为什么要将视图作为参数传递,我在onCreate()中调用了checkLoginType();
public void checkLoginType(View v)
{
Cursor c = db.rawQuery("select login_type password, pin_password from user_information", null);
while(c.moveToNext())
{
login_type = c.getString(0);
password = c.getString(1);
pin_password = c.getString(2);
}
if(login_type.equals("pin_password"))
{
info.setText("Enter your old pin");
old_password.setText("Confirm Pin");
old_password.setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD);
}
}