Isnt it
public class jmAdapter<Type> : ArrayAdapter<string> {
instead of
public class jmAdapter : ArrayAdapter<string> {
?
I personnaly subclass the BaseAdapter class with custum data classes :
public class SimpleListItemData
{
public SimpleListItemData(int key, string value)
{
Key = key;
Value = value;
}
public string Value { get; set; }
public int Key { get; set; }
}
public class SimpleListAdapter<Type> : BaseAdapter<SimpleListItemData>
{
private List<SimpleListItemData> _data;
private LayoutInflater inflater;
public SimpleListAdapter(Context context, List<SimpleListItemData>
data)
{
inflater = LayoutInflater.From(context);
_data = data;
}
public override SimpleListItemData this[int position]
{
get { return _data[position]; }
}
public override int Count
{
get { return _data.Count; }
}
public override long GetItemId(int position)
{
return _data[position].Key;
}
public override View GetView(int position, View convertView,
ViewGroup parent)
{
if (convertView == null)
{
convertView = inflater.Inflate(Resource.Layout.list_item,
null);
}
convertView.FindViewById<TextView>(Resource.Id.simple_list_item_lib).Text =
this._data[position].Value;
return convertView;
}
}
But Im no expert J
De : [email protected]
[mailto:[email protected]] De la part de John Murray
Envoyé : vendredi 21 octobre 2011 11:46
À : 'Discussions related to Mono for Android'
Objet : [mono-android] multi line list view and converting java
Can any kind soul help me the last few yards on this
I am experimenting with multi line listviews
Either is there any good tutorial/example especially for monodroid ?
I cant find anything other than java stuff which seems to say build your
own adapter
So I took this code ...java and converted it to c# - seems Ive got most
things nailed ive sorted the supers and extends and shoved the layout
inflater somewhere it can reach context etc but in VS 2010 I am getting a
weird error on the constructor line
'Android.Widget.ArrayAdapter<string>' does not contain a
constructor that takes 0 arguments on the constructor line
I dont get it my code doesnt have 0 arguments????
Oh BTW I changed the List<Orders> to List<string> just to keep it simple
while experimenting
I am sure Ive got some syntax wrong somewhere but I cant find anymore
hints so have come to a grinding halt.
I think Ive sorted all other issues out but can anyone look at my code and
advise if I am going in the right direction?
If theres no tutorials for mono on this(multi line listview) I am happy to
post any successful conclusion for the Wiki for anyone elses benefit
TIA
John Murray
==========================================
JAVA code
private class OrderAdapter extends ArrayAdapter<Order> {
private List<Order> items;
public OrderAdapter(Context context, int textViewResourceId,
ArrayList<Order> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup
parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Order o = items.get(position);
if (o != null) {
TextView tt = (TextView)
v.findViewById(R.id.toptext);
TextView bt = (TextView)
v.findViewById(R.id.bottomtext);
if (tt != null) {
tt.setText("Name: "+o.getOrderName());
}
if(bt != null){
bt.setText("Status: "+ o.getOrderStatus());
}
}
return v;
}
}
My c# CODE ====================================================
public class jmAdapter : ArrayAdapter<string> {
private List<string> items;
private LayoutInflater vi;
public jmAdapter(Context context, int textViewResourceId,
List<string> items) { //error on this line
base.jmAdapter(context, textViewResourceId, items);
//and on this
this.items = items;
vi=LayoutInflater.From(context);
}
public override View getView(int position, View convertView,
ViewGroup parent) {
View v = convertView;
if (v == null) {
//=
(LayoutInflater)GetSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.Inflate(Resource.Layout.custom_row_view, null);
}
string o = items.ElementAt(position);
if (o != null) {
TextView tt = (TextView)
v.FindViewById(Resource.Id.areg);
TextView bt = (TextView)
v.FindViewById(Resource.Id.atype);
if (tt != null) {
tt.SetText("Areg:
"+o,TextView.BufferType.Normal); }
if(bt != null){
bt.SetText("Atype: "+
o,TextView.BufferType.Normal);
}
}
return v;
}
}
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid