Because you never use parameter view
in method onClick
. But that default signature for this method.
for example, if you will use a parameter in a method, IntelliJ IDEA doesn't shows "Parameter never used"
public void onClick(View view) { // Parameter 'view' used
if(view.getId() == R.id.myId) //example start
{
Toast.makeText(this, "CorrectId", Toast.LENGTH_LONG).show();
} //example finish
Toast.makeText(this, "Hello", Toast.LENGTH_LONG).show();
}
Update:
For example you have 3 buttons in main layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn1"
android:onClick="onClick"
/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn2"
android:onClick="onClick"
/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/btn3"
android:onClick="onClick"
/>
</LinearLayout>
I your activity metod onClick handle events from three buttons. And we need to recognize that the button has been pressed.
public void onClick(View view) { // Parameter 'view' used
switch (view.getId())
{
case (R.id.btn1):
{
Toast.makeText(this, "Hello Button_1 pressed", Toast.LENGTH_LONG).show();
break;
}
case (R.id.btn2):
{
Toast.makeText(this, "Hello Button_2 pressed", Toast.LENGTH_LONG).show();
break;
}
case (R.id.btn3):
{
Toast.makeText(this, "Hello Button_2 pressed", Toast.LENGTH_LONG).show();
break;
}
}
This is one example of how you can use the 'view'