확장 할 클래스가 LinearLayout
입니다. 아래LinearLayout을 확장하는 동안 Textview의 값이 업데이트되지 않습니다.
코드는 : ->change()
방법이라고지고 onDraw()
이 때
class MyLinearLayout extends LinearLayout{
static TextView txt;
static Button btn;
static LayoutInflater inflater;
public MyLinearLayout(Context context) {
super(context);
// TODO Auto-generated constructor stub
View.inflate(context, R.layout.displayinfo, this);
inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
super.onLayout(changed, l, t, r, b);
}
public void change(){
View view =inflater.inflate(R.layout.displayinfo, null);
//Button btn = (Button) inflate(context, R.id.btn, null);
txt = (TextView) view.findViewById(R.id.textView1);
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
txt.setText("Changed");
}
};
//view.refreshDrawableState();
}
@Override
protected void onDraw(Canvas canvas) {
change();
}
}
그러나 값이 변경지고 있지 않습니다. 이보기를 WindowManager
에 추가합니다.
이 확장보기에서는 기본적으로 array
에서 값을 업데이트해야합니다. 그러나 문제는 루프를 계속 호출하는 방법입니다. invalidate()
을 호출하면 계속 호출 할 수 있지만 CPU 사용량이 늘어나고보기가 너무 빨리 새로 고쳐져 사용자가 실제로 View
을 볼 수 없게됩니다.
그래서 기본적으로 나는 두 가지 문제가 있습니다
1. TextView
위의 코드에서 업데이트 가져 오지?
2. invalidate()
메서드를 호출하지 않고 기본적으로 뷰 값을 지속적으로 업데이트하는 방법은 무엇입니까? 사전
나는 handler.sendEmptyMessage (0)을 두어 보았습니다. ,하지만 작동하지 않습니다. 우리가 처리기를 옆에두면 뷰의 데이터를 새로 고치는 다른 방법은 무엇입니까? – Robust