how to populate listview in xamarin android from web service data

Web Service is working but i have problem in xamarin code C#

public class ReturnData
{
public string Message;
public int UserID;
public int UserU_NO;
public int QtqSlit;
}

  [WebMethod(MessageName = "OrderStatusList", Description = "OrderStatusList new Order")]
[System.Xml.Serialization.XmlInclude(typeof(List<ReturnOrder>))]
public List<ReturnOrder> OrderStatusList(string JO)  /// get list of notes
{

    int QtqSlit = 0;
    int QtyPcs = 0;
    String Design = "";
    string Message = "";

    List<ReturnOrder> resultlist = new List<ReturnOrder>();

    SqlDataReader reader;
    using (SqlConnection connection = new SqlConnection(DBConnection.ConnectionString))
    {
        SqlCommand cmd = new SqlCommand("SELECT QtqSlit,QtyPcs,Design  FROM TestOrderStatus where [email protected]");
        cmd.CommandType = CommandType.Text;
        cmd.Connection = connection;
        cmd.Parameters.AddWithValue("@JO", JO);
        connection.Open();


        reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            QtqSlit = reader.GetInt32(0);
            QtyPcs = reader.GetInt32(1);
            Design = reader.GetString(2);
            ReturnOrder rt = new ReturnOrder();
            rt.Message = Message;
            rt.QtqSlit = QtqSlit;
            rt.QtyPcs = QtyPcs;
            rt.Design = Design;
            resultlist.Add(rt);
        }

        if (QtqSlit == 0)
        {
            Message = " user name or password is in correct";
        }
        reader.Close();

        connection.Close();
    }


    return resultlist;
}

Xamarin android Code :

namespace Printopack { [Activity(Label = "Mainlistview", Icon = "@drawable/icon")] public class Mainlistview : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);

    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Mainlistview);

    // Get our button from the layout resource,
    // and attach an event to it
    ListView ListView = FindViewById<ListView>(Resource.Id.listView1);



    Selling.WebServiceDB ws = new Selling.WebServiceDB();
    ws.OrderStatusListCompleted += Ws_OrderStatusListCompleted;
    ws.OrderStatusListAsync(Convert.ToString(1));


}


private void Ws_OrderStatusListCompleted(object sender, Selling.OrderStatusListCompletedEventArgs e)
{

    ListView ListView = FindViewById<ListView>(Resource.Id.listView1);
    string msg = "";


    if (e.Result.QtqSlit.ToString().Equals("0"))
    {
        msg = e.Result.Message;

    }
    else
    {


        // full class
        List<TableItem> tableItems = new List<TableItem>();
        tableItems.Add(new TableItem("" + e.Result.QtqSlit, "" + e.Result.QtyPcs, Resource.Drawable.Icon));

        ListView.Adapter = new HomeScreenAdapter(this, tableItems);


    }
    var callDialog = new AlertDialog.Builder(this);
    callDialog.SetTitle("Notify");
    callDialog.SetMessage(msg);
    callDialog.SetNeutralButton("Ok", delegate {

    });
    callDialog.Show();
}


// adpater manage
public class HomeScreenAdapter : BaseAdapter<TableItem>
{
    List<TableItem> items;
    Activity context;
    public HomeScreenAdapter(Activity context, List<TableItem> items)
        : base()
    {
        this.context = context;
        this.items = items;
    }
    public override long GetItemId(int position)
    {
        return position;
    }
    public override TableItem this[int position]
    {
        get { return items[position]; }
    }
    public override int Count
    {
        get { return items.Count; }
    }
    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        var item = items[position];
        View view = convertView;
        if (view == null) // no view to re-use, create new
            view = context.LayoutInflater.Inflate(Resource.Layout.Ticket_News, null);
        view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Heading;
        view.FindViewById<TextView>(Resource.Id.Text2).Text = item.SubHeading;
        view.FindViewById<ImageView>(Resource.Id.Image).SetImageResource(item.ImageResourceId);
        return view;
    }
}

public class TableItem
{
    public string Heading;
    public string SubHeading;
    public int ImageResourceId;
    public TableItem(string Heading, string SubHeading, int ImageResourceId)
    {
        this.Heading = Heading;
        this.SubHeading = SubHeading;
        this.ImageResourceId = ImageResourceId;
    }
}

}
}

Sign In or Register to comment.