package com.sometrik.framework;

import java.util.ArrayList;
import java.util.TreeMap;

import android.content.Context;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class FWPicker extends Spinner implements NativeMessageHandler {
  
  ArrayAdapter<String> adapter;
  ArrayList<Integer> numberList;
  TreeMap<Integer, String> valueMap;

  public FWPicker(Context context) {
    super(context);
    adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item);
    valueMap = new TreeMap<Integer, String>();
    numberList = new ArrayList<Integer>();
  }

  @Override
  public void handleMessage(NativeMessage message) {
    
    switch (message.getMessage()) {
    case ADD_OPTION:
      valueMap.put(message.getValue(), message.getTextValue());
      numberList.add(message.getValue());
      for (int i = 0; i < numberList.size(); i++) {
	adapter.add(valueMap.get(numberList.get(i)));
      }
      setAdapter(adapter);
      break;
    default:
      System.out.println("Message couldn't be handled by Picker");
      break;
    }
  }

  @Override
  public void showView() {
    
  }

  @Override
  public int getElementId() {
    return getId();
  }

}

@@ -115,24 +115,87 @@
 t.Context;%0D%0A
+import android.view.View;%0D%0Aimport android.widget.AdapterView;%0D%0A
 import andro
@@ -219,16 +219,16 @@
 apter;%0D%0A
-
 import a
@@ -328,24 +328,32 @@
 er %7B%0D%0A  %0D%0A  
+private 
 ArrayAdapter
@@ -373,16 +373,24 @@
 ter;%0D%0A  
+private 
 ArrayLis
@@ -415,16 +415,24 @@
 ist;%0D%0A  
+private 
 TreeMap%3C
@@ -458,16 +458,73 @@
 lueMap;%0D
+%0A  %0D%0A  private native void pickerOptionSelected(int id);%0D
 %0A%0D%0A  pub
@@ -709,24 +709,24 @@
 String%3E();%0D%0A
-
     numberLi
@@ -753,24 +753,344 @@
 nteger%3E();%0D%0A
+    %0D%0A    setOnItemSelectedListener(new OnItemSelectedListener() %7B%0D%0A%0D%0A      @Override%0D%0A      public void onItemSelected(AdapterView%3C?%3E arg0, View arg1, int position, long arg3) %7B%0D%0A%09pickerOptionSelected(position);%0D%0A      %7D%0D%0A%0D%0A      @Override%0D%0A      public void onNothingSelected(AdapterView%3C?%3E arg0) %7B%0D%0A      %7D%0D%0A    %7D);%0D%0A
   %7D%0D%0A%0D%0A  @Ov

Add onSelectedListener and native function call to picker