我有一个带有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线程中吗?
答案 0 :(得分:0)
解决了,只是在代码的其他部分搞乱了活动的内容视图