Android 我的自定义视图控件未在片段中重新绘制

Android 我的自定义视图控件未在片段中重新绘制,android,view,ondraw,invalidation,Android,View,Ondraw,Invalidation,我已经创建了自定义视图控件,它从视图控件扩展而来,只在onDraw方法中绘制了一些信息 如果我在常规活动布局上创建控件,一切都会正常工作。但如果我在片段的onCreateView()中创建此控件,它会在创建时绘制,然后我的视图“冻结”。它工作并解析,但不调用onDraw()。我试图调用invalidate(),但什么都没有 有什么想法吗 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa

我已经创建了自定义视图控件,它从
视图
控件扩展而来,只在
onDraw
方法中绘制了一些信息

如果我在常规活动布局上创建控件,一切都会正常工作。但如果我在片段的
onCreateView()
中创建此控件,它会在创建时绘制,然后我的视图“冻结”。它工作并解析,但不调用
onDraw()
。我试图调用
invalidate()
,但什么都没有

有什么想法吗

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)     {       
    final View v = inflater.inflate(R.layout.button, container, false);
    mAgatButton = (agatButton) v.findViewById(R.id.agatButton1);
    mAgatButton.setOnClickListener(new OnClickListener() {      
        @Override
        public void onClick(View view) {
            // This not Repainted           
            final GraphViewSeries TahoSer = mGraphTaho.getSeries((byte)0);
            mGraphTahoPos++;
            TahoSer.appendData(new GraphViewData(mGraphTahoPos, 50d), true);            
            //This Work correct
            mTahoLabel.setText(String.format(getString(R.string.button_rpm), (int)(Math.random()*1000)));

            Log.d(agatButton.class.toString(),"Click Detected: "+TahoSer.size());
        }
    });
    final Context context = getActivity().getApplicationContext();

    LinearLayout graphView = (LinearLayout) v.findViewById(R.id.graph_lay_taho);
    graphView.addView(mGraphTaho = getGraphView(context,"Taho"));

    mTahoLabel = (TextView) v.findViewById(R.id.tahoText);
    mTahoLabel.setText(String.format(getString(R.string.button_rpm), 0));

    return v;
}

private GraphView getGraphView(Context context, String Name)
  {
     final GraphView tmpView = new LineGraphView(context,Name);  
     tmpView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));

     List<GraphViewData> initalSeriesData = new ArrayList<GraphViewData>();
     for (byte i=0;i<20;i++)
         initalSeriesData.add(new GraphViewData(i, 0d));

     final GraphViewSeries tahoSeries = new GraphViewSeries(initalSeriesData);

     ((LineGraphView) tmpView).setDrawBackground(true);
     tmpView.addSeries(tahoSeries);
     tmpView.setViewPort(1, 20);
     tmpView.setScalable(false);
     tmpView.setManualYAxis(true);
     tmpView.setManualYAxisBounds(100, 0);

     return tmpView;
  }
public View onCreateView(布局充气机、视图组容器、捆绑包保存状态){
最终视图v=充气机充气(右布局按钮,容器,假);
mAgatButton=(agatButton)v.findViewById(R.id.agatButton 1);
mAgatButton.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图){
//这不是重新油漆的
final GraphViewSeries TahoSer=mGraphTaho.getSeries((字节)0);
mGraphTahoPos++;
TahoSer.appendData(新的GraphViewData(mGraphTahoPos,50d),真);
//这项工作是正确的
mTahoLabel.setText(String.format(getString(R.String.button_rpm),(int)(Math.random()*1000));
Log.d(agatButton.class.toString(),“检测到点击:”+TahoSer.size());
}
});
最终上下文=getActivity().getApplicationContext();
线性布局图视图=(线性布局)v.findViewById(R.id.graph\u lay\u taho);
addView(mGraphTaho=getGraphView(上下文,“Taho”);
mTahoLabel=(TextView)v.findViewById(R.id.tahoText);
mTahoLabel.setText(String.format(getString(R.String.button_rpm),0));
返回v;
}
私有GraphView getGraphView(上下文上下文,字符串名称)
{
final GraphView tmpView=新线图视图(上下文、名称);
tmpView.setLayoutParams(新的LayoutParams(LayoutParams.MATCH_父级,LayoutParams.MATCH_父级));
List initalSeriesData=new ArrayList();
对于(字节i=0;i