HuTcHx Posted June 27, 2012 Share Posted June 27, 2012 Bonjour, J'ai le code suivant (simple bouton qui augemente de taille dès qu'on appuie dessus). Mon soucis c'est que (Button) findViewById(R.id.bouton) est Null alors que R.id.bouton a bien une valeur. package sdz.chapitreDeux.Listener; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.Button; public class Appli3ListenerActivity extends Activity { private Button btDeformant = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //System.out.println("ok 1"); setContentView(R.layout.main); //System.out.println("ok 2"); //btDeformant = null; btDeformant = (Button) findViewById(R.id.bouton); //System.out.println("ok 3"); System.out.println(btDeformant); btDeformant.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { System.out.println("ok 4"); Button bouton = (Button) v; int largeur = bouton.getWidth(); int hauteur = bouton.getHeight(); float x = event.getX(); float y = event.getY(); bouton.setTextSize((Math.abs(x - largeur / 2) + Math.abs(y - hauteur / 2))); return true; } }); //setContentView(R.layout.main); } } Je ne comprend pas le problème :( Merci pour votre aide. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.