Ses propres ecouteur android

hjbb Messages postés 7 Statut Membre -  
hjbb Messages postés 7 Statut Membre -
Bonjour,

j'ai cree un Class herité du LineaireLayout, avec deux button "+" et "-" et un textview et je veux creer un ecoteur pour l'utiliser pour manipuler ce class,
ps: la solution du java ne fonctionne pas

1 réponse

  1. scinarf Messages postés 1183 Statut Membre 294
     
    Bonjour,

    Pourrais je vois voir votre code dans la Class, histoire de voir ou est le problème.
    Quel IDE utilisez vous ?
    Sur quel version(API) de Android vous de développer ?
    0
    1. hjbb Messages postés 7 Statut Membre
       
      android 2.1, eclipse
      package com.example.repondeur;  
       
      
      import android.content.Context;  
      import android.graphics.Color;  
      import android.util.AttributeSet;  
      import android.view.Gravity;  
      import android.view.View;  
      import android.widget.Button;  
      import android.widget.LinearLayout;  
      import android.widget.TextView;  
      
      
      public class Wheel extends LinearLayout {  
         
         
          Button up, down;  
       int max, min;  
       int wrap = LayoutParams.WRAP_CONTENT;  
       int fill = LayoutParams.FILL_PARENT;  
       TextView num;  
         
         
       public Wheel(Context context) {  
        super(context);  
        max = 10;  
        min = 1;  
        setOrientation(LinearLayout.VERTICAL);  
        setLayoutParams(new LayoutParams(wrap, wrap));  
        init();  
       }  
      
       public Wheel(Context context, AttributeSet attrs) {  
        super(context, attrs);  
        max = 10;  
        min = 1;  
        init();  
       }  
         
       //private void init(AttributeSet attrs) {}  
      
       public Wheel(Context context, int tmp, int tmp2) {  
        super(context);  
        max = tmp;  
        min = tmp2;  
        setOrientation(LinearLayout.VERTICAL);  
        setLayoutParams(new LayoutParams(wrap, wrap));  
        init();  
       }  
      
       private void init() {  
          
        Context ctx = this.getContext();  
        up = new Button(ctx);  
        down = new Button(ctx);  
        num = new TextView(ctx);  
          
        up.setText("+");  
        down.setText("-");  
        num.setText(Integer.toString(min));  
        num.setGravity(Gravity.CENTER);  
        num.setTextColor(Color.WHITE);  
        up.setOnClickListener(new OnClickListener() {  
           
         @Override  
         public void onClick(View v) {  
          int tmp = Integer.valueOf((String) num.getText()) + 1 ;  
          if (tmp > max){  
           tmp = min;  
          }  
          String chtmp = Integer.toString(tmp);  
          num.setText(chtmp);  
          //fireModifier(new ModifierEvent(Wheel.this, true));  
         }  
        });  
          
        down.setOnClickListener(new OnClickListener() {  
           
         @Override  
         public void onClick(View v) {  
          int tmp = Integer.valueOf((String) num.getText()) - 1 ;  
          if (tmp < min){  
           tmp = max;  
          }  
          String chtmp = Integer.toString(tmp);  
          num.setText(chtmp);  
          //fireModifier(new ModifierEvent(Wheel.this, false));  
         }  
        });  
          
          
        addView(up, new LinearLayout.LayoutParams(fill, wrap));  
        addView(num, new LinearLayout.LayoutParams(fill, wrap));  
        addView(down, new LinearLayout.LayoutParams(fill, wrap));  
          
       }  
         
       public int getNum(){  
        return Integer.valueOf(num.getText().toString());  
       }  
         
       public String getNumOnString(){  
        return num.getText().toString();  
       }  
         
       public void setMaxMin(int ma, int mi){  
        max = ma;  
        min = mi;  
       }  
         
      } 
      
      0
    2. scinarf Messages postés 1183 Statut Membre 294
       
      A partir de la quel est le problème ?
      0
    3. hjbb Messages postés 7 Statut Membre
       
      merci pour l'aide :)
      0
    4. scinarf Messages postés 1183 Statut Membre 294
       
      Tu as trouvé ton bonheur dans le lien que j'ai donné ?

      Voila qui pourra me servir plus tard.
      0