Vote count:
0
I want TextViews
to display the sensors readings in a Fragment
. When trying to initialize the SensorManager
the getSystemServices
is undefined in the Fragment
, eclipse says.Why and how to fix it.
Fragment
public class FragSensors extends Fragment {
private TextView accXTv, accYTv, accZTv;
private SensorManager sensorManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.frag_sensors, container, false);
accXTv = (TextView) v.findViewById(R.id.accXValue);
accYTv = (TextView) v.findViewById(R.id.accYValue);
accZTv = (TextView) v.findViewById(R.id.accZValue);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
}
private final SensorEventListener mSensorListener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
};
}
asked 41 secs ago
Aucun commentaire:
Enregistrer un commentaire