列表视图在主/详细信息视图一个细节片段 [英] Listview as a detail fragment in master/detail view

查看:107
本文介绍了列表视图在主/详细信息视图一个细节片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在创建从链接主/详细信息片段。这工作得很好,现在在这里,而不是详细片段类的TextView我想实现列表视图,(即)我想显示马西德威的细节作为一个孩子的ListView,所以我想
detail.xml:

Am creating a master/detail fragment from this link. This works fine, now here instead of textview in detail fragment class i would like to implement listviews, (ie) i would like to display the details of the masterview as a child listview, hence i tried detail.xml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ListView 
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:id="@+id/listview1"
            />"
 <ListView 
            android:layout_width="120dp"
            android:layout_height="wrap_content"
            android:id="@+id/listview2"
            />"

    </LinearLayout>

在我detailFragment类

and in my detailFragment class

public class DetailFragment1 extends ListFragment {
     @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      String[] values = new String[] { "1", "2", "3",
                "4"  };
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.simple_list_item_1, values);
              setListAdapter(adapter);

     }

我的问题是孩子的ListView显示的是在初始阶段,但我想,当我点击主page.Am新片段的第一排,所以帮我实现这个显示此列表视图。在此先感谢..

My problem is child listview is displaying at initial stage but i want to display this listview when i click the first row of master page.Am new to fragments, so help me in achieving this. Thanks in advance..

推荐答案

而不是做这样的,你可以设计,其中包含的ListView作为主站的FrameLayout容器的布局。在集装箱的FrameLayout,可以动态膨胀的布局,其目的是在这样你可以有孩子ListView和详细信息视图的方式。

Instead of doing like this, you can design a layout which contains ListView as master and frameLayout container. In frameLayout container, you can dynamically inflate layout, which is designed in such a way that you can have child listview and details view.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    tools:context=".NavigationActivity" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:background="@color/strip_background"
        android:layout_weight="1"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/nav_lv_transactions"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="none" >

        </ListView>

    </LinearLayout>

    <FrameLayout
        android:id="@+id/nav_fl_frag_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="14"
        android:background="@android:color/darker_gray" >

    </FrameLayout>

</LinearLayout>

在的onclick listerner把这个code,

In onclick listerner put this code,

Bundle arguments = new Bundle();
arguments.putString(ARG_ITEM_ID,
"Some Name");
MyClassFragment newFragment = new MyClassFragment();
newFragment.setArguments(arguments);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_fl_frag_container, newFragment);
transaction.commit();

试试这个。它将工作

Try this. It will work

这篇关于列表视图在主/详细信息视图一个细节片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆