【发布时间】:2014-05-20 15:26:41
【问题描述】:
我有以下问题:
我正在使用以下方式开发应用程序:
public class MainActivity extends FragmentActivity implements ActionBar.TabListener
这是使用ViewPager。所以最初的 main_activity.xml 是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none" >
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</RelativeLayout>
framgent_container.xml 包含以下内容
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/items_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/adv_image"
android:layout_width="fill_parent"
android:layout_height="56dp"
android:src="@drawable/no_adv" />
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/adv_image" />
</RelativeLayout>
所以问题来了: 我得到正确显示的列表和顶部的 adv_image。当我单击列表中的一项时,我可以看到应显示的项目。 (是一种线性布局,带有图像视图和滚动视图下方的描述)。 但是 当我单击图像视图(不可单击)时! 显示上一个列表的另一个项目。这让我假设 Listview 仍然存在(在我的文章后面?很奇怪)。即使我点击文章图片上方的一点点,它也会触发 adv_image url,它只存在于 listview 中,而不存在于这个片段中..
用文章片段替换列表视图的代码如下。
public class ArticlesListFragment extends ListFragment {
哪个 onCreateView 膨胀了以下内容
View rootView = inflater.inflate(R.layout.items_list, container, false);
具有以下功能
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Fragment fragment = null;
Bundle args = new Bundle();
fragment = new Article();
args.putString("unique_id", ((ArticleItem) v.getTag()).ID);
fragment.setArguments(args);
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.addToBackStack("HomePage");
ft.replace(R.id.fragment_container, fragment);
ft.commit();
}
所以有什么想法吗??????我试图替换几个不同的东西 onitemclick..但我仍然没有任何运气..
提前致谢!
【问题讨论】:
-
您是否在另一个
Fragment之上添加Fragment?ImageView位于Fragment之上?还是在ListView之上的ImageView? -
我有一个 FragmentList,它在 ListView 的顶部包含一个 imageView,并且一个 Fragment 的点击项替换了片段列表。这个新片段包含一个 ImageView 和一个 TextView 下方。
标签: android android-fragments android-listview android-viewpager