Dies ist mein erstes Mal mit einem ListView arbeiten und ich hatte einige Probleme. Ich bin mir sicher, dass ich eine Technik falsch implementiert habe. Nach vielen Suchen im Internet und dem Anschauen von Tutorials auf Listenansichten habe ich es noch nicht herausgefunden.ListView Creator aufgerufen, aber keine anderen Methoden
Dies wird gelegentlich angezeigt, die meiste Zeit jedoch startet es gerade nicht. Wenn es angezeigt wird, ist es wenn der Bildschirm ausgeschaltet ist und ich die App starte und den Gerätebildschirm einschalte und es die Liste anzeigt. Dies ist sehr getroffen und vermisse aber.
Der Konstruktor wird jedes Mal aufgerufen, danach werden Count und GetView jedoch nie aufgerufen.
Alles scheint in meiner main.axml Datei unter
<?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>
In meiner Haupttätigkeit werden Anzeigen ich alles durch und alles wird immer genannt verfolgt haben.
Um Ihnen einige Hintergrundinformationen zu geben, erstelle ich die Liste, die ich an den benutzerdefinierten Adapter sende, den ich verwende. Ich habe eine benutzerdefinierte Objekt RootObject genannt, die eine Liste von Elementen
var list = JsonConvert.DeserializeObject<RootObject>(response);
ListView myItems = FindViewById<ListView>(Resource.Id.itemView);
PIAdapter itemViewAdapter = new PIAdapter(this, list);
myItems.Adapter = itemViewAdapter;
hält Dies alles
Mein Adapter Constructor zu funktionieren scheint auch genannt wird, und ich kann 2 Artikel sind in meiner Liste bestätigen.
Wenn ich jedoch Console.WriteLine in Count und GetView 99% der Zeit einschließe, werden sie nie aufgerufen. Ich kann jedoch alle Felder im Konstruktor aufrufen und bestätigen, dass ich Werte eingegeben habe, und unter bestimmten Bedingungen wird es korrekt angezeigt.
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;
}
}
}
Falls es erforderlich ist, das ich bin die Bearbeitung der myItem.axml Datei
<?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>
welchen Wert in 'Console.WriteLine bekommen ("[Meine App] Schritt 10" + Liste .items.Count); '? –
Da ich vergessen habe, nach den 10 ein Leerzeichen einzufügen, bekomme ich das. 06-21 00: 56: 32.266 I/Mono-Stdout (21134): [Meine App] Schritt 102 – StevenDStanton
Wenn es hilft, ist dies meine Datenquelle. Es ist ein JSON mit 2 Elementen {"items": [{"barcode": "690443240066", "name": "gjjnn", "upvotes": "1", "downvotes": "0", "aktualisiert": "1466479409028"}, {"Barcode": "038000845031", "Name": "fhj", "upvotes": "2", "downvotes": "1", "aktualisiert": "1466396732038"}]} – StevenDStanton