Android TextView未在自定义视图中更新

Android TextView未在自定义视图中更新,android,android-fragments,textview,Android,Android Fragments,Textview,我有一个片段获取GPS信号并将结果发送到自定义视图 我可以显示从片段中获取的信号的输出,并看到它更新得很好。以下是片段1的代码: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { RelativeLayout view = (Relativ

我有一个片段获取GPS信号并将结果发送到自定义视图

我可以显示从片段中获取的信号的输出,并看到它更新得很好。以下是片段1的代码:

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

            RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.gps_stamp_fragment, container,false);
            RelativeLayout rl1 = new RelativeLayout(view.getContext());
            TextView tView1 = new TextView(view.getContext());
            tView1.setText("waiting...");  //this is the only thing custom view gets!
            rl1.addView(tView1);
            rl1.setId(1);
            tView1.setId(2);
            view.addView (rl1);

            lm =(LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, this);


            return view;
        }

//And here's where I get the GPS signal from and use setText again to update to the GPS signal.

   @Override
    public void onLocationChanged(Location arg0) {
        String lat = String.valueOf(arg0.getLatitude());

        RelativeLayout rl1 = (RelativeLayout) getView().findViewById(1);
        TextView tView1 = (TextView) rl1.findViewById(2);
        tView1.setText(lat);

    }
然后,在自定义视图中,我有以下代码,它查找相对布局和关联的文本视图,并获取文本

RelativeLayout rl1 = (RelativeLayout) getRootView().findViewById(1);
TextView tView1 = (TextView) rl1.findViewById(2);  
tView1.getText();
getRootView().invalidate();
问题是,此自定义视图中唯一出现的文本是“等待…”。GPS测量值从未出现

我在类似的问题中读到了我需要的。invalidate()视图,这就是我添加最后一行的原因,但这似乎对我不起作用

为什么从fragment1调用TextView时会正确更新,而从自定义视图调用时不会正确更新


谢谢。

无效的
应该在
onLocationChanged