视图可见性不会更改

时间:2015-07-22 23:49:53

标签: android android-layout android-view

我的java代码中有一个名为panel_close的按钮。在setOnclickListener方法中,我更新了一些其他视图的可见性。但是,有时候代码似乎没有正确更新面板的可见性。这是代码

panel_close.setOnClickListener(new OnClickListener() {


        @Override
        public void onClick(View v) {
            View temp=findViewById(R.id.show_panel);
            temp.startAnimation(window_close);
            temp.setVisibility(View.GONE);
            compass.setVisibility(View.VISIBLE); // compass is defined as a field. Sometimes the code does not make this view visible
            stats.setVisibility(View.VISIBLE); // stats is defined as a field. Sometimes the code does not make this view visible
            control.setVisibility(View.VISIBLE); // control is defined as a field. Sometimes the code does not make this view visible


            loadAllList(); // this is an AsyncTask
            loadAllpins(); // this is an AsyncTask

        }
    });

任何评论将不胜感激。

2 个答案:

答案 0 :(得分:0)

您应该查看在UI线程上运行这些更改,以确保修改对UI可见:

Android - using runOnUiThread to do UI changes from a thread

答案 1 :(得分:0)

你应该首先提供有关你的变量的详细信息,这可能会发生,因为你正在制作布局或类似的东西看不见或消失,孩子们在里面。这将使它们保持不可见。

相关问题