package com.sometrik.framework;

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

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class FWPicker extends Spinner implements NativeMessageHandler {
  
  private ArrayAdapter<String> adapter;
  private ArrayList<Integer> numberList;
  private TreeMap<Integer, String> valueMap;
  private final int id;
  
  private native void pickerOptionSelected(int id, int position);

  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>();
    id = this.getId();
    
    setOnItemSelectedListener(new OnItemSelectedListener() {

      @Override
      public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
	pickerOptionSelected(id, position);
      }

      @Override
      public void onNothingSelected(AdapterView<?> arg0) {
      }
    });
  }

  @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();
  }

}

@@ -326,24 +326,52 @@
 dler %7B%0D%0A  %0D%0A
+  private Context context;%0D%0A
   private Ar
@@ -399,16 +399,16 @@
 apter;%0D%0A
-
   privat
@@ -837,13 +837,8 @@
 d = 
-this.
 getI
@@ -839,24 +839,53 @@
 = getId();%0D%0A
+    this.context = context;%0D%0A
     %0D%0A    se
@@ -1309,24 +1309,24 @@
 ssage()) %7B%0D%0A
-
     case ADD
@@ -1335,16 +1335,106 @@
 PTION:%0D%0A
+      adapter = new ArrayAdapter%3CString%3E(context, android.R.layout.simple_spinner_item);%0D%0A
       va

Fix Picker option populating