这是我的第一个片段,它通过 xml 布局打开片段
public class ListFrag extends SherlockFragment implements OnItemClickListener
{
Context c;
List<ReferalRow> referal_RowItems;
DoctorDaoImpl doctorDao;
DoctorServiceImpl service;
DoctorValidator doctorValidator;
View layoutView;
ListView doctoListView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
layoutView = inflater.inflate(R.layout.activity_refer_mangmnt, null);
return layoutView;
}
这是我的activity_refer_mangmnt
.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2"
android:padding="2dp">
<ListView
android:id="@+id/listView_refer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:divider="@android:color/black"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/rightpanel_back">
<fragment
android:id="@+id/detail_fragment"
android:tag="detailfrag"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.app1.DetailsFrag" />
</LinearLayout>
`</LinearLayout>
这是我的 DetailFrag 课程
public class DetailsFrag extends SherlockFragment
{
ExpandableListView detailList;
TextView tvMessage;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
contentView = inflater.inflate(R.layout.activity_refer_view, null);
detailList = (ExpandableListView) contentView.findViewById(R.id.ep_detail_view);
tvMessage = (TextView)contentView.findViewById(R.id.tv_textView);
return contentView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
if(id==0)
{
detailList.setVisibility(View.GONE);
tvMessage.setText("Click on the item on the left panel to view the details");
}
else
{
detailList.setVisibility(View.VISIBLE);
tvMessage.setVisibility(View.GONE);
}
这是我在 LIstFrag 中的 onItem 点击监听器
FragmentTransaction ft = getFragmentManager().beginTransaction();
Fragment lastFrag = getFragmentManager().findFragmentByTag("detailfrag");
if(lastFrag!=null)
ft.remove(lastFrag);
Fragment fragment = Fragment.instantiate(c, DoctorDetailsFrag.class.getName(),arguments);
ft.replace(R.id.detail_fragment, fragment);
ft.commit();
我需要在单击列表中的项目后第一次在右侧面板中显示一条消息时,我想消失该消息。但是这里的消息没有从片段中删除。它显示在新片段的背景中。是吗?