2
(我不知道這是否允許在這裏,我是新的)微調不會響應點擊...即使onItemSelected被調用?
我在stackoverflow上發現了一個老問題,問題沒有得到正確的答案,而且我面對同樣的問題。因此,我真的很感激,如果有人可以看看它,非常感謝!
Spinner won't respond to clicks...even though onItemSelected is called?
UPDATE:
我自己的代碼,那麼我想,以防止通過在開始運行我onItemSelected()方法,所以我做一樣的人問這個問題。我嘗試了一下我的代碼,看看它是否會改變什麼,但沒有運氣..老實說,我不知道什麼是錯的,我仍然是一個初學者,所以我真的沒有線索做什麼..
這裏是我的代碼:
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) {
}
...
}
}
請更新問題與你有什麼treid和問題,而不是隻是鏈接到舊的問題。 – kosa