相关疑难解决方法(0)

从Thread更新UI

我想从更新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)

user-interface multithreading android

53
推荐指数
5
解决办法
14万
查看次数

没有使用相同项目调用Android Spinner OnItemSelected

首先,我知道这次被问了好几次,但是在较新的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)

android spinner android-spinner

11
推荐指数
1
解决办法
5833
查看次数