Salve a tutti!
Allora il mio problema e' questo:
devo realizzare un'Activity, con un'animazione, in modo tale che possa passare tra una schermata e un'altra della stessa activity, dopo aver selezionato un elemento presente in un menu spinner che raccoglie l'elenco dei sensori disponibili sul mobile.
Il problema e' che quando seleziono il sensore dal menu, non passa alla schermata successiva.
Suggerimenti?
Di seguito posto il codice scritto fin qui, se qualcuno ha suggerimenti
codice:
public class interfaceCSMAS extends Activity {
public Sensor selectedItem;
public String[] sensorArray = new String[]{""};
public List<Sensor> list;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set main.XML as the layout for this Activity
setContentView(R.layout.main);
SensorManager SM = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
list = SM.getSensorList(Sensor.TYPE_ALL);
TextView sensorTot = (TextView)findViewById(R.id.tv_sensor);
// sensor number...
sensorTot.setText(this.getString(R.string.nsensor)+": "+list.size()+"!");
int size = list.size();
String sensorList = new String("");
int i;
for (i=0; i<size; i++){
sensorList = " "+sensorList+list.get(i).getName();
sensorArray[i] = list.get(i).getName();
}
TextView sensorListView = (TextView)findViewById(R.id.tv_sensor_list);
if(i>0){
sensorList = getString(R.string.tv_sensor_list)+":\n"+ sensorList;
sensorListView.setText(sensorList);
}
// Add sensor list to the spinner
Spinner spinnerSensors = (Spinner) findViewById(R.id.spinner_sensor);
ArrayAdapter<String> sensorArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, sensorArray);
spinnerSensors.setOnItemSelectedListener(new myOnItemSelectedListener());
spinnerSensors.setAdapter(sensorArrayAdapter);
// Set the listener for Button_Next, a quick and dirty way to create a listener
Button buttonNext = (Button) findViewById(R.id.Button_next);
buttonNext.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the ViewFlipper from the layout
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
// Set an animation from res/anim
vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.fade));
vf.showNext();
}
});
// Set the listener for Button_Previous, a quick and dirty way to create a listener
Button buttonPrevious = (Button) findViewById(R.id.Button_previous);
buttonPrevious.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// Get the ViewFlipper from the layout
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
// Set an animation from res/anim
vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.fade));
vf.showPrevious();
}
});
}
//final Handler mHandler = new Handler();
// handler OnItemSelectedListener...
public class myOnItemSelectedListener implements OnItemSelectedListener{
public void onItemSelected(AdapterView<?> parent, View view,
int item, long arg3) {
selectedItem = list.get(item);
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
vf.setAnimation(AnimationUtils.loadAnimation(view.getContext(), R.anim.fade));
vf.showNext();
}
public void onNothingSelected(AdapterView<?> arg0) {
//
}
}
}