I created a button which changes its Image onClick. As I tried to add another Button which does exactly the same the app crashed.
I don´t know how to add a second or more Buttons which have an access to the onClick method. I found similar questions to this but nothing solved the Problem.
Here´s the code with the example. It works for 1 button.
code:
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.button3);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
b.setBackgroundResource(R.drawable.ic_launcher);
}
});
}
}