Benutzerdefinierte ArrayAdapter und Spinner. Keine item-Auswahl

Android 1.6
Gibt es eine Sammlung solcher Objekte

public class MyItem {
public String name = "";
public String brief = "";
     public int availiableweight = 0; 
public Node xmlpoint = null;

@Override
public String toString()
{
    return name;
}
public MyItem(String _brief, String _name, Node _xmlpoint)
{
    name = _name;
    brief = _brief;
    xmlpoint = _xmlpoint;
}
 }

Objekte wurden gespeichert im array: ArrayList itemsList

Elemente sind sichtbar in der dropdown-Liste der spinner, aber ich kann nicht wählen Sie ein beliebiges Element. Veranstaltung OnItemSelectedListener wird nicht generiert. Drehfeld-Steuerelement ist leer. Wo ist mein Fehler?

Code der Anwendung

public class MyActivity extends Activity {
/** Called when the activity is first created. */

private ArrayList<MyItem> itemsList;
private Spinner mySpinner;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mySpinner = (Spinner) findViewById(R.id.mySpinner);

    itemsList = new ArrayList<MyItem>();
    ArrayAdapter<MyItem> myAdapter = new ArrayAdapter<MyItem>(this, android.R.layout.simple_spinner_item, itemsList); 
    myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    mySpinner.setAdapter(myAdapter); 

    mySpinner.setOnItemSelectedListener(new OnItemSelectedListener() 
    {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) 
        {
            //TODO Auto-generated method stub
            AlertDialog("Pos: " + arg2);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) 
        {
            //TODO Auto-generated method stub
        }
    });
    itemsList.add(new MyItem("1","one",null));
    itemsList.add(new MyItem("2","two",null));
    itemsList.add(new MyItem("3","three",null));
}  
}

layout main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/languageText"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Language" android:gravity="center_vertical"/>

    <Spinner
        android:id="@+id/languageSpinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" android:prompt="@string/chooseitem"/>

</LinearLayout>

</LinearLayout>
InformationsquelleAutor Foxbox | 2012-01-03
Schreibe einen Kommentar