Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 3rd, 2012, 08:27 AM   #1 (permalink)
New Member
 
Join Date: Jan 2012
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom ArrayAdapter и Spinner. Cant select item

Android 1.6
There's a collection of such objects
Code:
 
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;
 }
}
Objects were stored in array: ArrayList<MyItem> itemsList
Items are visible in dropdown list of spinner, but i cant select any item. Event OnItemSelectedListener is not generated. Spinner control is empty. Where is my fault?

Code of application

Code:
 
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

Code:
 
<?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>

a123send is offline  
Reply With Quote
Sponsors
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:02 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo