2013-10-05 1 views
0

으로 호출되지 않습니다. 그래서 onDraw()가 호출되지 않습니다.findSellectedBt()에서 invalidate라고하는 findsellectedtBt()가 작동하지 않으면 android invalidate 함수가

왜 이러한 코드가 올바르게 작동하지 않습니까?

public class CustomView extends View { 



private Typeface t; 
private Paint paint; 
private Buttons sellectedBt; 


public CustomView(Context context) { 
    ... } 

public CustomView(Context context, AttributeSet attrs) { 
...} 

public CustomView(Context context, AttributeSet attrs, int defStyle) { 
...} 

@Override 
protected void onDraw(Canvas canvas) { 
    if(isInEditMode()) return ; 

    canvas.drawColor(Color.YELLOW); 

    switch(sellectedBt) { 
     case ID: 
      t = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL); 
      paint.setTypeface(t); 
      canvas.drawText("ID: 0000", 50, 100, paint); 
     case PHOTO: 
        break; 
     case LINE: 
      break; 
     default: 
      break; 
    } 
} 

public void findSellectedBt(Buttons buttonId) { 
    sellectedBt = buttonId; 
    invalidate(); 
} 

은}

공용 클래스 MainActivity는 활동 {

private CustomView customView; 
private Button btId; 
private CheckBox btPhoto; 
private ToggleButton btLineOff; 
private Button btClaer; 
private ToggleButton btBlue; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    customView = new CustomView(this); 

    btId = (Button)findViewById(R.id.id); 
    btPhoto = (CheckBox)findViewById(R.id.photo); 

    btId.setOnClickListener(new OnClickListener() { 
     public void onClick(View v){ 
      System.out.println("idOnclick"); 
      customView.findSellectedBt(Buttons.ID); 

     } 
    }); 

    btPhoto.setOnCheckedChangeListener(new OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton arg0, boolean arg1) { 
      // TODO Auto-generated method stub 
      System.out.println("photoChecked"); 

      if(arg1 == true) 
       customView.findSellectedBt(Buttons.PHOTO); 
     } 
    }); 


} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

}

패키지 com.example.hw4_200921275을 확장;

공공 열거 버튼 {ID, 사진, LINE, CLEAR, BLUE}

+0

무효화를 호출 할 때 ... 별도의 스레드 또는 UI 스레드에서 호출해야합니까? –

+0

별도의 스레드와 UI 스레드를 구분할 수 없습니다. 차이점은 무엇입니까? – user2841650

+0

어디에서'findSellectedBt'를 호출할까요? – ssantos

답변

0

더블 당신이 어딘가에 그런데

findSellectedBt(buttonsObject); 

를 호출하고 확인 Sellected에서 오타를 확인합니다.

관련 문제