我想从更新Progressbar的Thread更新我的UI.不幸的是,当从"runnable"更新进度条的drawable时,进度条消失了!改变进度onCreate()栏的绘图可用于其他工作!
有什么建议?
public void onCreate(Bundle savedInstanceState) {
res = getResources();
super.onCreate(savedInstanceState);
setContentView(R.layout.gameone);
pB.setProgressDrawable(getResources().getDrawable(R.drawable.green)); //**Works**/
handler.postDelayed(runnable, 1);
}
private Runnable runnable = new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run()
{
//* The Complete ProgressBar does not appear**/
pB.setProgressDrawable(getResources().getDrawable(R.drawable.green));
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 首先,我知道这次被问了好几次,但是在较新的android平台上,看起来建议的解决方案不起作用(正如其他人所说的那样).我需要我的微调器仍然调用OnItemSelected,即使用户选择了两次相同的项目.我已经设法找到这个应该做的伎俩:
public class NDSpinner extends Spinner {
private int lastSelected = 0;
private static Method s_pSelectionChangedMethod = null;
static {
try {
Class noparams[] = {};
Class targetClass = AdapterView.class;
s_pSelectionChangedMethod = targetClass.getDeclaredMethod("selectionChanged", noparams);
if (s_pSelectionChangedMethod != null) {
s_pSelectionChangedMethod.setAccessible(true);
}
} catch( Exception e ) {
Log.e("Custom spinner, reflection bug:", e.getMessage());
throw new RuntimeException(e);
}
}
public NDSpinner(Context context) {
super(context);
}
public NDSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NDSpinner(Context context, AttributeSet attrs, int defStyle) { …Run Code Online (Sandbox Code Playgroud)