>
Boa tarde!
No meu projeto existem dois spinner e queria gravar os itens de cada um deles, mas não estou a conseguir.
Então o xml é o seguinte:
[XML]
android:layout_width="wrap_content"
android:layout_height="match_parent" >
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center_horizontal"
android:layout_column="0"
android:text="@string/tvNiveldeiniciativa"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_horizontal"
android:prompt="@string/iniciativa_prompt"
android:entries="@array/iniciativa_arrays" />
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center_horizontal"
android:layout_column="0"
android:text="@string/tvNíveldeEnvolvimento"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_horizontal"
android:prompt="@string/iniciativa_prompt"
android:entries="@array/iniciativa_arrays" />
[/XML]
android:id="@ id/TableLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
android:id="@ id/Niveldeiniciativa"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:id="@ id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center_horizontal"
android:layout_column="0"
android:text="@string/tvNiveldeiniciativa"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
android:id="@ id/iniciativa_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_horizontal"
android:prompt="@string/iniciativa_prompt"
android:entries="@array/iniciativa_arrays" />
android:id="@ id/NivelEnvolvimento"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
android:id="@ id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:gravity="center_horizontal"
android:layout_column="0"
android:text="@string/tvNíveldeEnvolvimento"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium" />
android:id="@ id/envolvimento_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="center_horizontal"
android:prompt="@string/iniciativa_prompt"
android:entries="@array/iniciativa_arrays" />
DBAdapter datasource;
/////-/////-/////-/////
Spinner iniciativa_spinner;
int ValorSelecionado;
/////-/////-/////-/////
/////-/////-/////-/////
Spinner envolvimento_spinner;
int ValorSelecionado1;
/////-/////-/////-/////
Button btOK;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.ctos);
/////-/////-/////-/////
iniciativa_spinner = (Spinner) findViewById(R.id.iniciativa_spinner);
iniciativa_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapter, View v,
int position, long id) {
ValorSelecionado = Integer.parseInt(adapter.getItemAtPosition(position).toString());
Toast.makeText(adapter.getContext(), "Selecionou: " ValorSelecionado,
Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView> arg0) {
// TODO Auto-generated method stub
}
});
/////-/////-/////-/////
/////-/////-/////-/////
envolvimento_spinner = (Spinner) findViewById(R.id.envolvimento_spinner);
envolvimento_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> adapter, View v,
int position, long id) {
ValorSelecionado1 = Integer.parseInt(adapter.getItemAtPosition(position).toString());
Toast.makeText(adapter.getContext(), "Selecionou: " ValorSelecionado1,
Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView> arg0) {
// TODO Auto-generated method stub
}
});
/////-/////-/////-/////
/////-/////-/////-/////
btOK = (Button) findViewById(R.aluno.btOK);
btOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
datasource.open();
Session s = datasource.createSession( ValorSelecionado, ValorSelecionado1 );
datasource.close();
AlertDialog.Builder dialogo = new
AlertDialog.Builder(Ctos.this);
dialogo.setTitle("Aviso");
dialogo.setMessage("Nível de iniciativa:" s.getNiveliniciativa());// s.getId()
//String.valueOf(ValorSelecionado));
/* dialogo.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//finish();
}
});
dialogo.show();*/
dialogo.setCancelable(false);
dialogo.setPositiveButton("Continuar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, close
// current activity
dialog.cancel();
}
});
dialogo.setNegativeButton("Sair", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
finish();
}
});
dialogo.show();
}
}
});
/////-/////-/////-/////
Ola Cristiana
kd os dados p vc colocar no spinner??
Nível de iniciativa
Nível de iniciativa
- 1
- 2
- 3
- 4
Nível de Envolvimento
Nível de Envolvimento
- 1
- 2
- 3
- 4
- 5
[XML]
[/XML]
Cristiana,
onde é q tu ta inserindo esses valores??