ListView不在xamarin

时间:2016-01-22 18:38:06

标签: c# android android-fragments xamarin android-viewpager

我在viewpager和listview中找到了一些问题。一切正常,但我在列表视图中看不到任何行只有页面上的textview。但是,当我只加载寻呼机项目的视图时,一切都显示良好。我正在寻找一些答案,但我无法找到任何形式的工作。也许你可以帮助我。

我的pagerview的主要布局如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0e0e0e"
    android:id="@+id/sample_main_layout">
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />
    <FrameLayout
        android:id="@+id/sample_content_fragment"
        android:layout_weight="2"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:minWidth="25px"
        android:minHeight="25px" />
    <EditText
        android:id="@+id/etSearch"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="@drawable/edit_text_style"
        android:hint="Szukaj produktu..."
        android:textColor="#000"
        android:visibility="invisible" />
</LinearLayout>
<!-- Menu -->
<ListView
    android:id="@+id/leftListView"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:choiceMode="singleChoice"
    android:divider="#D2D2D2"
    android:dividerHeight="2dp"
    android:textColor="#0e0e0e"
    android:background="#F2F2F2" />
<!-- Koszyk -->
<ListView
    android:id="@+id/rightListView"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:choiceMode="singleChoice"
    android:divider="#D2D2D2"
    android:dividerHeight="2dp"
    android:textColor="#0e0e0e"
    android:background="#F2F2F2" />
</android.support.v4.widget.DrawerLayout>

然后使用寻呼机进行片段布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
    <Login.SlidingTabScrollView
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="@android:color/white" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>

和寻呼机项目布局:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myDrawer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:id="@+id/llContainer">
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:background="#E2E2E2"
            android:weightSum="100">
            <TextView
                android:text="Nazwa Produktu"
                android:id="@+id/txtNProduktu"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_weight="50"
                android:gravity="left"
                android:textColor="#000"
                android:textSize="16sp" />
            <TextView
                android:text="Ocena"
                android:id="@+id/txtOProduktu"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_weight="50"
                android:gravity="right"
                android:textColor="#000"
                android:textSize="16sp" />
</LinearLayout>
        <View
            android:layout_height="2dp"
            android:layout_width="match_parent"
            android:background="#000" />
        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/listView"
            android:background="#F2F2F2"
            android:divider="#101010"
            android:dividerHeight="1dp" />
    </LinearLayout>
    <EditText
        android:id="@+id/etSearch"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="@drawable/edit_text_style"
        android:hint="Search Friends"
        android:textColor="#000"
        android:visibility="invisible" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>

我在MainActivity中获得了一个片段事务:

Android.App.FragmentTransaction transaction = FragmentManager.BeginTransaction();
        SlidingTabsFragment fragment = new SlidingTabsFragment();
        transaction.Replace(Resource.Id.sample_content_fragment, fragment);
        transaction.Commit();

片段活动:

     public class SlidingTabsFragment : Fragment
{
    private SlidingTabScrollView mSlidingTabScrollView;
    private ViewPager mViewPager;
    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.Inflate(Resource.Layout.fragment_sample, container, false);
    }

    public override void OnViewCreated(View view, Bundle savedInstanceState)
    {
        mSlidingTabScrollView = view.FindViewById<SlidingTabScrollView>(Resource.Id.sliding_tabs);
        mViewPager = view.FindViewById<ViewPager>(Resource.Id.viewpager);

        mViewPager.Adapter = new SamplePagerAdapter();

        mSlidingTabScrollView.ViewPager = mViewPager;
    }
    public class SamplePagerAdapter : PagerAdapter
    {
        List<string> items = new List<string>();
        public SamplePagerAdapter() : base()
        {
            items.Add("Kategoria_1");
            items.Add("Kategoria_2");
            items.Add("Kategoria_3");
            items.Add("Kategoria_4");
            items.Add("Kategoria_5");
        }

        public override int Count
        {
            get
            {
                return items.Count;
            }
        }
        public override bool IsViewFromObject(View view, Java.Lang.Object obj)
        {
            return view == obj;
        }
        public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
        {
            View view = LayoutInflater.From(container.Context).Inflate(Resource.Layout.pager_item,container,false);
            container.AddView(view);



            return view;
        }
        public string GetHeaderTitle(int position)
        {
            return items[position];
        }

        public override void DestroyItem(ViewGroup container, int position, Java.Lang.Object obj)
        {
            container.RemoveView((View)obj);
        }
    }
}

在fragmet类中我有一个寻呼机适配器,它的工作正常,但没有包含数据的行形成我的listview。我为寻呼机项目创建了一个类,我不知道是正确的,但我不知道我应该把代码放在哪里。如果有人可以帮助我,那个项目就是git了! https://github.com/Poli143/Login

0 个答案:

没有答案