Sirgue Posted May 19, 2012 Share Posted May 19, 2012 Salut salut, J'ai eu une petite erreur dans mon code aujourd'hui, je ne sais pas trop comment la réparer mais je pense que ça vient plutôt de Java en lui même ^^" public class MainActivity extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Définition des boutons Button bouton1 = (Button)findViewById(R.id.bouton1); //Mise en écoute des boutons bouton1.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case bouton1.getId(): //code code code... } Link to comment Share on other sites More sharing options...
FickTiff Posted May 19, 2012 Share Posted May 19, 2012 public class MainActivity extends Activity /** Called when the activity is first created. */ Button bouton1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); addListenerOnButton(); } public void addListenerOnButton() { final Context context = this; //Définition des boutons bouton1 = (Button)findViewById(R.id.bouton1); //Mise en écoute des boutons bouton1.setOnClickListener(this); @Override public void onClick(View v) { switch (v.getId()) { case bouton1.getId(): //code code code... } Essaye comme cela Et si tu pourrais donner ton erreur sa pourrait aider à t'aider aussi ;) Link to comment Share on other sites More sharing options...
Sirgue Posted May 22, 2012 Author Share Posted May 22, 2012 En faite, cette erreur venait de "case bouton1.getId()". Vu que bouton1.getId() n'est pas une constante, ça veut pas. Il faut utiliser R.id.bouton1 ! :) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.