0
一個全局變量,我得到了以下問題:安卓:寫從onItemSelected()方法
請看看我的代碼
公共無效onItemSelected(適配器視圖父,觀景,INT位置,長的id){
Spinner spinner = (Spinner) findViewById(R.id.spinnerMonth);
Spinner spinner2 = (Spinner) findViewById(R.id.spinnerDay);
switch (parent.getId())
{
case R.id.spinnerMonth:
String monthstring = spinner.getItemAtPosition(position).toString();
switch (monthstring)
{
case "Januar": month = 1; break;
case "Februar": month = 2; break;
case "März": month = 3; break;
case "April": month = 4; break;
case "Mai": month = 5; break;
case "Juni": month = 6; break;
case "Juli": month = 7; break;
case "August": month = 8; break;
case "September": month = 9; break;
case "Oktober": month = 10; break;
case "November": month = 11; break;
case "Dezember": month = 12; break;
}
break;
case R.id.spinnerDay:
day = Integer.parseInt(spinner2.getItemAtPosition(position).toString());
break;
}
TextView textDate = (TextView) findViewById(R.id.textDate);
textDate.setText(""+month+"---"+day);
}
私人無效setEvents(){
String date = ""+day+"."+month+".";
//String date = ""+this.getDate();
textLine1.setText(date);
裏面onItemSelected米方法我得到了正確的月份和日期值 - 但在setEvents方法中,我得到了0和0的月份和日期值。這兩個變量都聲明爲全局變量。
我在哪裏錯過了什麼?當您從微調月份和日期
謝謝你幫我出 邁克爾