【问题标题】:Android GUI refresh (no threads used)Android GUI 刷新(未使用线程)
【发布时间】:2016-09-04 18:21:34
【问题描述】:

我有一个带有 AutoCompleteTextView(文本)的活动。

当我选择一个项目时,会执行以下代码:

 text.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Bundle args= new Bundle();

            for (Student s: studentsBook.getStudentsList()){

                if (s.getName().equals(((TextView)view).getText().toString())){

                    args.putSerializable("Student",s);
                    break;
                }
            }

            theLayout.setVisibility(View.GONE); //removing elements (button, textviews...) 
            addButton.setVisibility(View.GONE); //removing elements

            //simply adding a fragment through supportfragmentmanager and fragment transactions
//Fragment receives arguments (args) which contain a string to be showed.
//A tag: "DataFragment" is provided in order to get the fragment back in other parts of code.
//getMainView returns the container in which the fragment has to be created/showed.
            dataFragment=(StudentDataFragment)addFragment(StudentDataFragment.class,R.layout.student_data_fragment,getMainView().getId(),args,"DataFragment");
        }
    });

片段只有这个方法:

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    myLayout=(ViewGroup)inflater.inflate(R.layout.student_data_fragment,container,false);

    student=(Student)getArguments().getSerializable("Student");
    tv=((TextView)myLayout.findViewById(R.id.textView17));
    tv.setText(student.toString());
    return myLayout;
}

我看不到字符串,似乎 gui 没有更新,但如果发生方向变化,字符串就会出现..

我还管理后退按钮以删除片段(如果存在)并将元素设置为“消失”可见。代码运行成功,但似乎没有运行 gui 刷新。

在这种情况下不涉及线程,所以我认为我们在 UI 线程中对吗?

【问题讨论】:

    标签: android multithreading user-interface fragment


    【解决方案1】:

    已解决,只是在代码的其他部分搞乱了activity的内容视图

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      相关资源
      最近更新 更多