gpt4 book ai didi

java - Android 旋转器

转载 作者:行者123 更新时间:2023-12-01 05:51:30 25 4
gpt4 key购买 nike

我正在旋转器中工作..我有三个旋转器,我将在第一个旋转器中显示天(即)1,2,3,4,5...30,31,在第二个旋转器中显示月份(i,e)1,2,3,...11,12 和第三个旋转器 2010 中的年份,...我想要的是我想在第 1、2、3 个中显示当前日期、月份、年份页面加载时的微调器响应..从中可以选择任何日、月、年这是我的代码::

public class NoteEdit extends Activity implements OnItemSelectedListener {

private EditText mTitleText;
private EditText mBodyText;
private Long mRowId;
private NotesDbAdapter mDbHelper;
private String array_spinner[];
private int currentDayOfMonth=0;
private int currentDayOfDays=0;
private final String[] months = {"1","2","3","4","5","6","7","8","9","10","11","12"};
Spinner s1,s,s2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDbHelper = new NotesDbAdapter(this);
mDbHelper.open();
setContentView(R.layout.note_edit);

Calendar cal = Calendar.getInstance();
cal.set(Calendar.MONTH,month);//month starts from 0
cal.set(Calendar.YEAR,year);
int noOfDayInMonthyear = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
Log.v("noOfDayInMonthyear",""+noOfDayInMonthyear);

ArrayList<Integer> obj=new ArrayList();
ArrayList<Integer> obj1=new ArrayList();
for(int i=1;i<=noOfDayInMonthyear;i++){
obj.add(i);
}
Log.v("Size",""+obj.size());
for(int i=2010;i<=2020;i++){
obj1.add(i);
}
Log.v("Size1",""+obj1.size());
s = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,obj);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
s.setOnItemSelectedListener(NoteEdit.this);

s1 = (Spinner) findViewById(R.id.Spinner02);
ArrayAdapter adapter1 = new ArrayAdapter(this,android.R.layout.simple_spinner_item,months);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter1);
s1.setOnItemSelectedListener(NoteEdit.this);

s2 = (Spinner) findViewById(R.id.Spinner03);
ArrayAdapter adapter2 = new ArrayAdapter(this,android.R.layout.simple_spinner_item,obj1);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter2);
s2.setOnItemSelectedListener(NoteEdit.this);
s2.setAdapter(adapter2);



mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);

Button confirmButton = (Button) findViewById(R.id.confirm);

mRowId = savedInstanceState != null ? savedInstanceState.getLong(NotesDbAdapter.KEY_ROWID)
: null;
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras.getLong(NotesDbAdapter.KEY_ROWID)
: null;
}

populateFields();

confirmButton.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {
setResult(RESULT_OK);
finish();
}

});
}


public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {

}


public void onNothingSelected(AdapterView<?> arg0) {


}

最佳答案

如果我理解你的问题正确,我想你是在问如何设置每个微调器的值?

找出您要为每个微调器选择的值,然后为每个微调器执行类似的操作 http://developer.android.com/reference/android/widget/AbsSpinner.html#setSelection(int , boolean 值)

 int dateId = <date id in the spinner>;
s2.setSelection(dateId);

关于java - Android 旋转器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4547844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com