Note that there are some explanatory texts on larger screens.

plurals
  1. POTextView not updating in custom View
    primarykey
    data
    text
    <p>I have a fragment that acquires the GPS signal and sends the result to a custom view. </p> <p>I can display the output from the signal acquired in the fragment and see that it updates just fine. Here's the code for fragment1:</p> <pre><code> @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); } </code></pre> <p>Then, in the custom view I have the following code which finds the relative layout and associated text view and gets the text.</p> <pre><code>RelativeLayout rl1 = (RelativeLayout) getRootView().findViewById(1); TextView tView1 = (TextView) rl1.findViewById(2); tView1.getText(); getRootView().invalidate(); </code></pre> <p>The problem is that the only text that ever appears in this custom view is the "waiting...". The GPS measurements never appear.</p> <p>I have read in similar questions that I need to .invalidate() the view which is why I added the last line, but this did not seem to work for me.</p> <p>Why does the TextView update properly when called from fragment1, but not when called from the custom view?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload