【发布时间】: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