I'm trying to implement Yuri Kanivets' Android wheel picker. I am simply trying to place a few strings onto a single wheel. What makes my implementation a little different is that I am trying to display the wheel on an AlertDialog.Builder. I can get an empty wheel to appear on my dialog, but I can't seem to populate it with anything. Every time I try to add values to the wheel, I get a null pointer exception.
If anyone is familiar with this, can you see what I am doing wrong? I strongly suspect that the context that I am using in my ArrayWheelAdapter is wrong, but I don't know how else to do it. Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_events);
LayoutInflater inflater = LayoutInflater.from(this);
builderView = inflater.inflate(R.layout.wheel_range_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(builderView);
alert = builder.create();
final WheelView range = (WheelView) findViewById(R.id.range);
int defaultRange = 0;
String ranges[] = new String[] {"10 miles", "25 miles", "50 miles", "Everywhere"};
ArrayWheelAdapter<String> adapter = new ArrayWheelAdapter<String>(this, ranges);
adapter.setTextSize(18);
//this next line is where it is crashing -- maybe adapter is null???
range.setViewAdapter(adapter);
range.setCurrentItem(defaultRange);
alert.show();
}
use
final WheelView range = (WheelView)builderView. findViewById(R.id.range);
instead of
final WheelView range = (WheelView) findViewById(R.id.range);
for initializing WheelView range
instance because WheelView View is in DialogBox wheel_range_layout
layout instead of Activity layout