I make a Button and I want to make onClick method in XML
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/button2"
android:onClick="maysara"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_marginTop="63dp" />
Then I go to Java code to make the method "maysara"
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void maysara(View v){
**if(v.getId()==findViewById(R.id.button2))**
Toast.makeText(this,"button2",Toast.LENGTH_SHORT).show();}}
But I got an error in if statement >>> I really dont know why @?!