嗨,大家好我正在開發一個應用程序。我想用它從紡紗人中選擇他/她的生日。我將根據spinner3更改天數。如果用戶選擇一個有30天的月份,我的應用程序需要設置微調器4只包含高達30的數字。當用戶選擇一個微調器項目3時,我需要此設置。 但我的應用程序崩潰時,我打開它。它不會崩潰,如果我註釋掉這一行: spinner3.setOnItemSelectedListener(this);(解決了這個)嘗試setOnItemSelectedListener(this)時應用程序崩潰;
新的問題:它運行onItemSelected(適配器視圖父,觀景,詮釋POS,長ID)唯一的
希望你能找到的問題。由於
SignUp2.java:
package com.geniboys.sosyaaal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class SignUp2 extends Activity implements
AdapterView.OnItemSelectedListener {
Spinner spinner4 = (Spinner) findViewById(R.id.spinner4);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
Spinner spinner3 = (Spinner) findViewById(R.id.spinner3);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up2);
ActionBar actionBar = getActionBar();
actionBar.hide();
List<String> list = new ArrayList<String>();
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
for(int i = 1972; i <= year+4; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(dataAdapter);
spinner3.setOnItemSelectedListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sign_up2, menu);
return true;
}
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
// An item was selected. You can retrieve the selected item using
String ay = (String) parent.getItemAtPosition(pos);
List<String> list = new ArrayList<String>();
if(ay == "Ocak" || ay == "Mart" || ay == "Mayıs" || ay == "Temmuz" || ay == "Ekim" || ay == "Aralık")
{
for(int i = 1; i<=31; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
if(ay == "Şubat")
{
for(int i = 1; i<=28; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
else
{
for(int i = 1; i<=30; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(SignUp2.this, android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner4.setAdapter(dataAdapter);
}
@Override
public void onNothingSelected(AdapterView<?> arg0)
{
}
public void geri(View view)
{
super.onBackPressed();
}
public void ileri(View view)
{
}
}
activity_sign_up2.xml:
<RelativeLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/registerbackground"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SignUpActivity" >
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView4"
android:layout_alignRight="@+id/editText1"
android:onClick="ileri"
android:text="@string/layoutIleri"
android:textColor="#ffffff" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="70dp"
android:text="@string/loginTanim"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="@string/loginKayit"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView4"
android:layout_alignLeft="@+id/textView1"
android:onClick="geri"
android:text="@string/layoutGeri"
android:textColor="#ffffff" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:hint="@string/loginAdhint"
android:textColor="#ffffff" />
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/editText1"
android:layout_alignTop="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:textColor="#ffffff" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView2"
android:layout_alignLeft="@+id/textView1"
android:layout_alignRight="@+id/textView2"
android:textColor="#ffffff"
android:ems="10" >
</EditText>
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_toRightOf="@+id/editText2"
android:textColor="#ffffff"
android:ems="10" />
<requestFocus />
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/spinner2"
android:layout_alignTop="@+id/textView2"
android:entries="@array/loginSehirler"
android:prompt="@string/loginMemlekethint"
android:textColor="#ffffff" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/TextView01"
android:layout_below="@+id/editText3"
android:layout_marginTop="24dp"
android:text="@string/loginMemleket"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner2"
android:layout_toLeftOf="@+id/spinner2"
android:text="@string/loginDogumTarihi"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/textView4"
android:layout_below="@+id/spinner1"
android:text="@string/loginMezuniyet"
android:textColor="#ffffff"
android:textSize="20sp" />
<Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/TextView01"
android:layout_marginTop="11dp"
android:layout_toLeftOf="@+id/editText3"
android:entries="@array/loginAylar"
android:prompt="@string/loginAylarhint" />
<Spinner
android:id="@+id/spinner5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/spinner4"
android:layout_alignLeft="@+id/spinner2"
android:layout_alignParentRight="true" />
<Spinner
android:id="@+id/spinner4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/spinner3"
android:layout_alignTop="@+id/spinner3"
android:layout_toLeftOf="@+id/spinner5"
android:layout_toRightOf="@+id/spinner3" />
</RelativeLayout>
編輯:添加的logcat:
01-23 18:31:49.730: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
01-23 18:31:49.730: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
01-23 18:31:53.150: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
01-23 18:31:57.930: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
01-23 18:32:00.270: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
01-23 18:32:10.310: W/InputEventReceiver(28607): Attempted to finish an input event but the input event receiver has already been disposed.
編輯:添加ANSWER
我不能回答我的問題。請添加這個屁股的答案:
在此更改if語句:
if(ay == "Ocak" || ay == "Mart" || ay == "Mayıs" || ay == "Temmuz" || ay == "Ekim" || ay == "Aralık")
{
for(int i = 1; i<=31; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
if(ay == "Şubat")
{
for(int i = 1; i<=28; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
else
{
for(int i = 1; i<=30; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
到
if(ay.equals("Ocak") || ay.equals("Mart") || ay.equals("Mayıs") || ay.equals("Temmuz") || ay.equals("Ekim") || ay.equals("Aralık"))
{
for(int i = 1; i<=31; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
else if(ay.equals("Şubat"))
{
for(int i = 1; i<=28; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
else
{
for(int i = 1; i<=30; ++i)
{
String foo = Integer.toString(i);
list.add(foo);
}
}
那裏面並宣佈方法紡紗解決了這個問題。感謝所有幫助過的人。
嗨!請檢查adb日誌,看看你得到了什麼樣的錯誤信息。 – Bex
您還應該複製LogCat所說的...... – thelawnmowerman
您的紡紗商爲空。 – Submersed