我想用微调器设置一个值,然后在我的 onClick 方法中将远程视图 TextView(在小部件上)的文本大小设置为所选值。我该怎么做?
谢谢
我试过了:
String selected;
Context context = WidgetConfig.this;
static Spinner spinner;
...
spinner.setOnItemSelectedListener(this);
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
Log.v(TAG, "OnItemselected started");
switch (position) {
case 0:
selected = "10".toString();
Break;
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
View.OnClickListener mOnClickListener = new View.OnClickListener() {
public void onClick(View v) {
Log.v(TAG, "set remote view");
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Log.v(TAG, "set txt size");
/* without this line*/ float number = Float.valueOf(selected.toString());
/* and this line, it runs fine */ views.setFloat(R.id.tvConfigInput, "setTextSize", number);
...
}
};
更新:
我两次声明了字符串,所以我修复了它,现在它没有崩溃,但它不起作用。文字大小没有改变..怎么办?