问候我正在尝试使用xamarin开发Android应用程序,其中布局具有视图分页器,其中包含8个元素,每个元素都包含列表视图...每个事情都可以正常地遵循教程{{3} } 但列表视图不会出现 这是我的列表视图的axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:fitsSystemWindows="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:textColor="#ffffffff" />
<CheckBox
android:text="@string/Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox1"
android:textColor="#ffffffff" />
<CheckBox
android:text="alert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:textColor="#ffffffff" />
</LinearLayout>
<ListView
android:id="@+id/newsFeedList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="10.0sp" />
</LinearLayout>
这是我的listview单元的axml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/contentImageView1"
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="50dp"
android:layout_height="50dp" />
<TextView
android:id="@+id/contentTextView1"
android:text="Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff" />
</LinearLayout>
以下是我的viewpager片段代码
using System;
using Android.Support.V4.App;
using Android.Support.V4.View;
using Android.App;
using Android.Views;
using Android.OS;
using Android.Widget;
using Android.Content;
namespace test
{
public class ContentFragment : Android.Support.V4.App.Fragment
{
private ViewPager homeViewPager;
public ContentFragment ()
{
}
override public View OnCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
var rootView = inflater.Inflate(Resource.Layout.HomeContent, container,false);
homeViewPager = rootView.FindViewById<ViewPager> (Resource.Id.homeViewPager);
homeViewPager.Adapter = new HomePagerAdapter (MainActivity.fragmentManager);
return rootView;
}
}
}
以下是我的视图寻呼机适配器
using System;
using Android.Support.V4.App;
namespace test
{
public class HomePagerAdapter:FragmentPagerAdapter
{
public HomePagerAdapter (FragmentManager fm):base(fm)
{
}
public override int Count {
get {
return 8;
}
}
public override Fragment GetItem (int position)
{
//return ListFragment;
return new FeedsFragment ();
//return f;
}
}
}
以下是我的listview片段代码
namespace test
{
public class FeedsFragment:Fragment
{
ListView feedsList;
List<FeedsModel>modelList;
FeedsModel model;
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Android.OS.Bundle savedInstanceState)
{
try{
View rootView = inflater.Inflate (Resource.Layout.NewsFeedList, container, false);
model = new FeedsModel ();
modelList=new List<FeedsModel>();
feedsList = rootView.FindViewById<ListView> (Resource.Id.newsFeedList);
for (int i = 0; i < 5; i++) {
model.feedContent="once upon the time tow boys and a girl saied bla bla bla and did blablablab and tha't some text yup uakfjjkd;f";
model.imageURI = "g";
modelList.Add(model);
}
feedsList.Adapter = new FeedsAdapter (MainActivity.context, modelList);
return rootView;}
catch(Exception e){{
Toast.MakeText (MainActivity.context, e.Message, ToastLength.Long).Show();
return base.OnCreateView (inflater, container, savedInstanceState);}
}
}
}
}
以下是listview的适配器
amespace test
{
public class FeedsAdapter:BaseAdapter<FeedsModel>
{ private Activity activity;
private List<FeedsModel> data;
public FeedsAdapter (Activity activity, List<FeedsModel> data):base()
{
// TODO Auto-generated constructor stub
this.activity = activity;
this.data = data;
}
public override long GetItemId(int position)
{
return position;
}
public override FeedsModel this[int position] {
get { return data[position]; }
}
public override int Count {
get { return data.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView; // re-use an existing view, if one is available
if (view == null) // otherwise create a new one
view = activity.LayoutInflater.Inflate(Resource.Layout.NewsFeedListItem, null);
Toast.MakeText (activity, "tetet", ToastLength.Long).Show ();
view.FindViewById<TextView>(Resource.Id.contentTextView1).Text = data[position].feedContent;
view.FindViewById<ImageView> (Resource.Id.contentImageView1).SetImageResource(Resource.Drawable.Icon);
return view;
}
}
}
最后是我的数据模型
using System;
namespace test
{
public class FeedsModel
{
private String _imageURI;
public String imageURI{
set{this._imageURI=value;}
get{return this._imageURI;}
}
private String _feedContent;
public String feedContent{
set{this._feedContent=value;}
get{return this._feedContent;}
}
public FeedsModel ()
{
}
}
}
感谢您提前的帮助
答案 0 :(得分:0)
非常确定您在根布局中不小心将android:orientation
设置为horizontal
而不是vertical
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" <-- Set this to vertical
android:fitsSystemWindows="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:textColor="#ffffffff" />
<CheckBox
android:text="@string/Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox1"
android:textColor="#ffffffff" />
<CheckBox
android:text="alert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkBox2"
android:textColor="#ffffffff" />
</LinearLayout>
<ListView
android:id="@+id/newsFeedList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="10.0sp" />
</LinearLayout>