( I don’t know if this is allowed here or not, I’m new)
I found an old question here on stackoverflow, the question didn’t get a correct answer, and I’m facing the same problem. I would therefore really appreciate, if someone could take a look at it, Thank you very much!
Spinner won't respond to clicks…even though onItemSelected is called?
UPDATE:
My own code, well I wanted to prevent my onItemSelected() method from running through at start, so I did the same as the guy asking that question. I’ve tried moving a bit round on my code, seeing if it would change anything, but no luck.. Honestly I have no idea whats wrong, and I’m still a beginner, so I doesn’t really have a clue on what to do..
Here is my Code:
public class WidgetConfig extends Activity implements OnItemSelectedListener{
static EditText info;
private static final String[] paths = { "10", "12", "14", "16", "18", "20",
"22", "24", "26", "28", "30", "32", "34", "36", "38", "40", "50", "60"};
private static final String TAG = "MyActivity";
int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
private ArrayList<String> mMyTypes = null;
private ArrayAdapter<String> mMyAdapter = null;
private Spinner mMyTypeSpinner = null;
// hack for spinner
boolean isFirstRunWithSpinner = true;
public WidgetConfig() {
super();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.v(TAG, "onCreate() started");
setContentView(R.layout.widgetconfig);
context = WidgetConfig.this;
// back button = cancel
setResult(RESULT_CANCELED);
//--------------------------------------------------
mMyTypeSpinner = (Spinner) findViewById(R.id.TxtSizeSP);
mMyTypes = new ArrayList<String>();
mMyTypes.add("Test string");
mMyAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, paths);
mMyAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mMyTypeSpinner.setAdapter(mMyAdapter);
// spinner listener
mMyTypeSpinner.setOnItemSelectedListener(this);
} // onCreate finished
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
Log.v(TAG, "OnItemselected started");
if( isFirstRunWithSpinner ) { isFirstRunWithSpinner = false; return; }
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
switch (position) {
case 0:
info.setTextSize(10.0f);
views.setFloat(R.id.tvConfigInput, "setTextSize", 10);
Log.v(TAG, "position 0 chosed");
break;
...
break;
case 17:
info.setTextSize(28.0f);
views.setFloat(R.id.tvConfigInput, "setTextSize", 60);
break;
}
//update widget with spinner input
Log.v(TAG, "update size start");
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Log.v(TAG, "update size over");
}
public void onNothingSelected(AdapterView<?> arg0) {
}
...
}
}
Have you tried this ? :