У меня есть следующий код:Ошибка кнопки Android onClick?
в OnCreate метод:
{
saveClick = (Button) findViewById(R.id.saveBtn);
saveClick.setOnClickListener(this);
}
@Override
public void onClick(View v) {
//------------ take input data and save in DB --------------------
String cpassword;
EditText num_1=(EditText)findViewById(R.id.num1);
EditText num_2=(EditText)findViewById(R.id.passkey1);
EditText num_3=(EditText)findViewById(R.id.passkey2);
number=num_1.getText().toString();
password=num_2.getText().toString();
cpassword=num_3.getText().toString();
DBoperation db=DBoperation.getInstance(getApplicationContext());
if(password == cpassword)
{
TelephonyManager tMgr =(TelephonyManager)getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
pnumber = tMgr.getLine1Number();
db.addSIMSs(pnumber);
db.addSIMSs(number);
db.addPassKey(password);
}
}
Я использую затмение для развития, и продолжает давать следующие ошибки: в строке: saveClick.setOnClickListener (это);
Ошибка:
Метод setOnClickListener (View.setOnClickListener) в представлении типа не применим для аргументов.
также в строке: общественного недействительными OnClick (Просмотр объем) {
ошибка:
метод OnClick (Просмотр) типа MainActivity необходимо переопределить или реализовать метод супертипом.
Ниже приведен XML-файл:
<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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="113dp"
android:text="TextView" />
<EditText
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="38dp"
android:layout_marginTop="37dp"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/passkey1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/num1"
android:layout_below="@+id/num1"
android:layout_marginTop="86dp"
android:ems="10"
android:inputType="textPassword" />
<EditText
android:id="@+id/passkey2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/passkey1"
android:layout_below="@+id/passkey1"
android:layout_marginTop="49dp"
android:ems="10"
android:inputType="textPassword" />
<TextView
android:id="@+id/pass1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/passkey1"
android:layout_alignLeft="@+id/textView2"
android:layout_marginBottom="35dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/pass2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_alignTop="@+id/passkey2"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/pass1"
android:layout_below="@+id/textView1"
android:layout_marginTop="24dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/passkey2"
android:layout_marginLeft="14dp"
android:layout_marginTop="41dp"
android:text="@string/save" />
</RelativeLayout>