我想做的是如果其他声明的旋转器。我宣布“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”。
当我点击“八月”时,它会给我MainActivity.java,否则它会给我August.java。现在,我的旋转器是自动选择,意思是,当我加载页面时,它将自动为我选择“六月”。有没有办法,让我禁用自动选择?
这是我的密码
String [] months = {
"June",
"July",
"August",
"Septemeber",
"November",
"December",我的date.java的一部分
//SpinnerView
s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, months);
s1.setAdapter(adapter);
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2, long arg3) {
int index = s1.getSelectedItemPosition();
//Toast.makeText(getBaseContext(), "You have seleted item :" + months[index] , Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?>arg0) {}
});
if ( s1.equals("August")) {
startActivity(new Intent(date.this,MainActivity.class));
}
else{
startActivity(new Intent(date.this,august
.class));
}发布于 2013-08-16 04:56:49
试试这个:
添加数组,如“选择月份”、“6月”、“7月”、“8月”、“9月”、“10月”、“11月”、“12月”
并登记入住
s1.setOnItemSelectedListener(new OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> arg0,View arg1, int arg2, long arg3) {
int index = s1.getSelectedItemPosition();
if(index>0)
{
String Month = MonthArray[index];
if ( Month.equalIgnoreCase("August")) {
startActivity(new Intent(date.this,MainActivity.class));
}
else{
startActivity(new Intent(date.this,august
.class));
}
}
}
public void onNothingSelected(AdapterView<?>arg0) {}
});希望能帮上忙!
发布于 2013-08-16 05:08:03
也许这会有帮助
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class date extends Activity implements AdapterView.OnItemSelectedListener{
ArrayList<String> months;
Spinner spinner;
ArrayAdapter<String> month_adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
months = new ArrayList<String>();
months.add("Select");
months.add("June");
months.add("July");
months.add("August");
months.add("Septemeber");
months.add("November");
months.add("December");
spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
month_adapter=new ArrayAdapter<String>(getBaseContext(),android.R.layout.simple_spinner_item, months);
month_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(month_adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onItemSelected(AdapterView<?> arg0, View v, int position,
long arg3) {
// TODO Auto-generated method stub
if(!(spinner.getSelectedItem().toString().trim().equals("Select")))
{
if ( spinner.getSelectedItem().toString().trim().equals("August")) {
startActivity(new Intent(date.this,MainActivity.class));
}
else{
startActivity(new Intent(date.this,august
.class));
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}发布于 2013-08-16 04:54:45
您需要将Spinner上一次选定的项位置存储在DB中或SharedPreference中。当应用程序加载时,请检查您在DB中还是在SharedPreference中的项位置,然后根据该位置在Spinner中选择项。
https://stackoverflow.com/questions/18265963
复制相似问题