我有listview。我用适配器填充它但它不可点击。我有检查列表视图不为空。 我在Activity中有Listview人口代码 它由DemoAdapter使用Another视图填充。
这是活动代码
var listView = FindViewById<ListView>(Resource.Id.menuListRestaurent);
DemoAdapter adapter = new DemoAdapter(this, mItems);
listView.Adapter = new DemoAdapter(this, mItems);
listView.ItemClick += (object sender, AdapterView.ItemClickEventArgs e) =>
{
var t = mItems[e.Position];
int id = t.ProductId;
var activity2 = new Intent(this, typeof(SingleProductDetailActivity));
activity2.PutExtra("MyData", id);
StartActivity(activity2);
};
这是Listview
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="@android:color/transparent"
android:id="@+id/menuListRestaurent" />
<?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"
android:background="@color/lightgray">
<ScrollView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:backgroundTint="#ff81d4fa">
<ImageView
android:id="@+id/Icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/blue"
android:textSize="20dip" />
<TextView
android:id="@+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dip"
android:textColor="@color/blue" />
</LinearLayout>
</TableLayout>
</ScrollView>
</LinearLayout>
Demo Adpater
{
public class DemoAdapter : BaseAdapter<ProductModel>
{
public List<ProductModel> mItems;
private Context mContext;
public DemoAdapter(Context context, List<ProductModel> items)
{
mContext = context;
mItems = items;
}
public override int Count
{
get
{
return mItems.Count;
}
}
public override long GetItemId(int position)
{
return position;
}
public override ProductModel this[int position]
{
get
{
return mItems[position];
}
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
//var view = mContext.LayoutInflater.Inflate(Resource.Layout.ImageAndSubTitle, null);
//var item = GetItem(position);
//view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Item1;
//view.FindViewById<TextView>(Resource.Id.Text2).Text = item.Item2;
//view.FindViewById<ImageView>(Resource.Id.Icon).SetImageResource(item.Item3);
//view.FindViewById<CheckBox>(Resource.Id.checkBox1).Clickable = true;
//return view;
View row = convertView;
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.ImageAndSubTitle, null, false);
}
TextView txtName = row.FindViewById<TextView>(Resource.Id.Text1);
txtName.Text = mItems[position].ProductName;
TextView txtPrice = row.FindViewById<TextView>(Resource.Id.Text2);
txtPrice.Text = Convert.ToString(mItems[position].ProductPrice);
//ImageView imgFood = row.FindViewById<ImageView>(Resource.Id.Icon);
//imgFood.SetImageResource(Resource.Id.Icon);
return row;
}
}
}
答案 0 :(得分:1)
ListView listview= (ListView) view.findViewById(R.id.ratingListViewId);
final Adapter adapter = new Adapter(mItems,getApplicationContext());
listview.setAdapter(listview);
adapter.notifyDataSetChanged();
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> adapterView, View view, final int i, long l) {
}
});