取代我有以下問題: 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,該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'嗎?一個'Fragment'頂部的ImageView?或在ListView頂部的ImageView? – Emmanuel
我有一個FragmentList,它包含一個ListView頂部的imageView,並且一個片段替代了片段列表。這個新的片段包含一個ImageView和一個TextView下面。 –