Я пытаюсь изменить текст с TextView
, который находится в Fragment
, когда вызывается функция onLocationChanged
.
Я знаю, что мог бы реализовать LocationListener
при создании HomeFragment
, но я хочу, чтобы это было модульным.
public void onLocationChanged(Location location) {
Log.i(TAG,"onLocationChanged method called");
HomeFragment hf = new HomeFragment();
if(hf == null)
{
Log.i(TAG,"hf is null");
}
else {
if(hf.getView().findViewById(R.id.speed_box) == null)
{
Log.i(TAG,"findViewById failed");
}
else {
TextView speedBox = (TextView) hf.getView().findViewById(R.id.speed_box);
if (location == null) {
if (speedBox != null) {
speedBox.setText("unknown m/s");
} else {
Log.i(TAG, "speedBox object is null");
}
} else {
Log.i(TAG, "onLocationChanged method called, the speed is: " + location.getSpeed());
float speed = location.getSpeed();
if (speedBox != null) {
speedBox.setText(location.getSpeed() + " m/s");
}
{
Log.i(TAG, "speedBox object is null");
}
}
}
}
}