これは私の初めてのListViewでの作業ですが、何か問題がありました。私は技術が正しく実装されていないと確信しています。しかし、多くのインターネット上で検索し、リストビューでチュートリアルを見て、私はまだそれを理解していない。ListView Creatorが呼び出されましたが、他のメソッドはありません
しかし、ほとんどの場合、これは時々開始されないことがあります。それが表示されているときは、画面がオフになっているとき、私はアプリを実行し、デバイスの画面をオンにすると、リストが表示されます。これは非常にヒットし、しかし逃す。
コンストラクタは毎回呼び出されますが、CountとGetViewが呼び出されることはありません。
すべてが、私はを通じてすべてをトレースしている私のメインの活動では
<?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>
の下に私のmain.axmlファイルに表示されているようだし、すべてが呼び出さなっています。
ここで私が使用しているカスタムアダプタに送信するリストを作成する方法を説明します。私はすべてが
マイアダプタコンストラクタも呼ばれていると私のリストにある、私は2つの項目を確認することができます動作するようですアイテム
var list = JsonConvert.DeserializeObject<RootObject>(response);
ListView myItems = FindViewById<ListView>(Resource.Id.itemView);
PIAdapter itemViewAdapter = new PIAdapter(this, list);
myItems.Adapter = itemViewAdapter;
これのリストを保持しているRootObjectというカスタムオブジェクトを持っています。
ただし、Console.WriteLineをCountおよびGetViewに含めると、99%の時間は呼び出されません。しかし、私はコンストラクタのすべてのフィールドを呼び出して、値が埋め込まれていることを確認することができ、特定の条件下では適切に表示されます。
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;
}
}
}
それが必要とされる場合には、私は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>
'Console.WriteLineを( "[私のアプリ]ステップ10" +リストになってどのような値.Items.Count); '? –
私は10の後にスペースを入れるのを忘れてしまったので、私はこれを手に入れました。 06-21 00:56:32.266 I/mono-stdout(21134):[マイアプリ]ステップ102 – StevenDStanton
これが私のデータソースです。これは、2つの項目{項目:{{"バーコード": "690443240066"、 "名前": "gjjnn"、 "アップボート": "1"、 "downvotes": "0"、 "updated" "1466479409028"}、{"barcode": "038000845031"、 "名前": "fhj"、 "upvotes": "2"、 "downvotes": "1"、 "updated": "1466396732038"}}} – StevenDStanton