Đây là lần đầu tiên tôi làm việc với một ListView và tôi đã gặp một số rắc rối. Tôi chắc chắn rằng tôi có một kỹ thuật được triển khai không chính xác. Tuy nhiên, sau khi tìm kiếm nhiều trên internet và xem các hướng dẫn trên các khung nhìn danh sách, tôi vẫn chưa tìm ra nó.ListView Creator được gọi nhưng không có phương pháp nào khác
Điều này đôi khi sẽ hiển thị, tuy nhiên, phần lớn thời gian nó không bắt đầu. Khi nó hiển thị nó là khi màn hình tắt và tôi chạy ứng dụng và bật màn hình thiết bị và nó hiển thị danh sách. Điều này là rất hit và bỏ lỡ mặc dù.
Trình xây dựng đang được gọi mỗi lần, tuy nhiên, sau đó Đếm và GetView không bao giờ được gọi.
Tất cả mọi thứ dường như được hiển thị trong tập tin main.axml của tôi dưới đây
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:p1="http://schemas.android.com/apk/res/android"
p1:orientation="vertical"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/linearLayout1">
<Spinner
p1:layout_width="match_parent"
p1:layout_height="50.5dp"
p1:id="@+id/stores"
p1:layout_marginBottom="16.0dp" />
<Button
p1:id="@+id/scanItem"
p1:layout_width="fill_parent"
p1:layout_height="wrap_content"
p1:text="Scan Item" />
<ListView
p1:minWidth="25px"
p1:minHeight="25px"
p1:layout_width="match_parent"
p1:layout_height="match_parent"
p1:id="@+id/itemView" />
</LinearLayout>
Trong hoạt động chính của tôi, tôi đã bắt nguồn từ tất cả mọi thứ thông qua và mọi thứ đều bị gọi.
Để cung cấp cho bạn một số thông tin cơ bản ở đây là cách tôi tạo danh sách tôi gửi qua bộ tiếp hợp tùy chỉnh mà tôi đang sử dụng. Tôi có một đối tượng tùy chỉnh được gọi RootObject chứa một danh sách các mục
var list = JsonConvert.DeserializeObject<RootObject>(response);
ListView myItems = FindViewById<ListView>(Resource.Id.itemView);
PIAdapter itemViewAdapter = new PIAdapter(this, list);
myItems.Adapter = itemViewAdapter;
này tất cả dường như làm việc
My Adaptor Constructor thậm chí còn được gọi và tôi có thể khẳng định 2 mặt hàng nằm trong danh sách của tôi.
Tuy nhiên, khi tôi bao gồm Bảng điều khiển.WriteLine in Count và GetView 99% thời gian chúng không bao giờ được gọi. Tuy nhiên, tôi có thể gọi tất cả các trường trong hàm tạo và xác nhận rằng tôi có các giá trị được điền vào và trong một số điều kiện nhất định, nó hiển thị đúng.
public class PIAdapter : BaseAdapter
{
RootObject list = new RootObject();
Activity context;
public PIAdapter(Activity context, RootObject list)
{
this.list = list;
this.context = context;
Console.WriteLine("[My App] Step 10" + list.items.Count);
}
public override int Count
{
get
{
return list.items.Count;
}
}
public override Java.Lang.Object GetItem(int position)
{
return null;
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
Console.WriteLine("[My App] - Step 11");
View view = convertView;
if(view == null)
{
view = context.LayoutInflater.Inflate(Resource.Layout.myItem, null);
}
var item = list.items[position];
ImageView customImage = view.FindViewById<ImageView>(Resource.Id.customImage);
TextView customName = view.FindViewById<TextView>(Resource.Id.customName);
TextView customBarcode = view.FindViewById<TextView>(Resource.Id.customBarcode);
TextView customUp = view.FindViewById<TextView>(Resource.Id.customUpVote);
TextView customDown = view.FindViewById<TextView>(Resource.Id.customDownVote);
customName.Text = item.name;
customBarcode.Text = item.barcode;
customUp.Text = item.upvotes;
customDown.Text = item.downvotes;
//Koush.UrlImageViewHelper.SetUrlDrawable(customImage, "http://api.myurl.com/images/" + item.barcode + ".png", Resource.Drawable.myicon);
return view;
}
}
}
Trong trường hợp nó là cần thiết Tôi đang chỉnh sửa này để bao gồm các tập tin myItem.axml
<?xml version="1.0" encoding="utf-8"?>
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relativeLayout1">
<ImageView
android:src="@android:drawable/ic_menu_gallery"
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/customImage" />
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/customImage"
android:id="@+id/customBarcode" />
<TextView
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/customBarcode"
android:id="@+id/customName"
android:layout_toRightOf="@id/customImage" />
<ImageView
android:src="@drawable/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/customImage"
android:id="@+id/customUp"
android:layout_below="@id/customName" />
<TextView
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/customUp"
android:id="@+id/customUpVote"
android:layout_below="@id/customName" />
<ImageView
android:src="@drawable/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/customUpVote"
android:id="@+id/customDown"
android:layout_below="@id/customName" />
<TextView
android:text="0"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/customDown"
android:id="@+id/customDownVote"
android:layout_below="@id/customName" />
</RelativeLayout>
</LinearLayout>
những gì giá trị nhận được trong 'Console.WriteLine ("[My App] Bước 10" + danh sách .items.Count); '? –
Vì tôi quên để bao gồm một không gian sau khi 10 tôi nhận được điều này. 06-21 00: 56: 32.266 I/mono-stdout (21134): [Ứng dụng của tôi] Bước 102 – StevenDStanton
Nếu nó giúp đây là nguồn dữ liệu của tôi. Đó là một json với 2 mục {"items": [{"barcode": "690443240066", "name": "gjjnn", "upvotes": "1", "downvotes": "0", "updated": "1466479409028"}, {"mã vạch": "038000845031", "tên": "fhj", "upvotes": "2", "downvotes": "1", "updated": "1466396732038"}]} – StevenDStanton