Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

convert java code to C#

alinjojobaalinjojoba INMember ✭✭

public class SMSimpleCursorAdapter extends SimpleCursorAdapter{

Cursor c;
Context context;
Activity activity;

public SMSimpleCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {
    super(context, layout, c, from, to);

    this.c = c;
    this.activity=(Activity) context;

EditEntries dbDel = new EditEntries(); //from previous code sample

public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null)
        convertView = View.inflate(context, R.layout.entries_list_item, null);
    View row = convertView;


    TextView score = (TextView) convertView.findViewById(;
    TextView time = (TextView) convertView.findViewById(;
    TextView id = (TextView) convertView.findViewById(;


    String daTag = c.getString(1);

    ImageButton delButton = (ImageButton) convertView.findViewById(;
    delButton.setOnClickListener(new OnClickListener() { //Click listener fro delete button
         public void onClick(View view) {
             dbDel.delRow(); //this is "delete row" method from previos code                    sample




  • alinjojobaalinjojoba INMember ✭✭
    edited June 2013

    I have done that :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Android.App;
    using Android.Content;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    using Android.Database;
    namespace AndroidApplication1
        public class SMSimpleCursorAdapter : SimpleCursorAdapter
            ICursor c;
            Context context;
            Activity activity;
            int idS;
            public SMSimpleCursorAdapter(Context context, int layout, ICursor c, string[] from, int[] to)
                : base(context, layout, c, from, to)
                this.c = c;
                this.context = context;
                this.activity = (Activity)context;
            public override View GetView(int position, View convertView, ViewGroup parent)
                if (convertView == null)
                    convertView = View.Inflate(context, Resource.Layout.listenentry, null);
                View row = convertView;
                //TextView score = (TextView) convertView.FindViewById(Resource.Id.tvIdShow);
                TextView time = (TextView)convertView.FindViewById(Resource.Id.tvPersonShow);
                TextView id = (TextView)convertView.FindViewById(Resource.Id.tvIdShow);
                id.SetText(c.GetString(0), TextView.BufferType.Normal);
                time.SetText(c.GetString(1), TextView.BufferType.Normal);
                String daTag = c.GetString(1);
                // ImageButton delButton = (ImageButton)convertView.FindViewById(Resource.Id.delButton);
                Button delButton = (Button)convertView.FindViewById(Resource.Id.delButton);
                delButton.Focusable = true;
                delButton.Clickable = true;
                delButton.Click += new EventHandler(delButton_Click);
                return (row);
            public override void BindView(View view, Context context, ICursor cursor)
                //if (view == null)
                //    view = View.Inflate(context, Resource.Layout.listenentry, null);
                //View row = view;
                ////TextView score = (TextView) convertView.FindViewById(Resource.Id.tvIdShow);
                //TextView time = (TextView)view.FindViewById(Resource.Id.tvPersonShow);
                //TextView id = (TextView)view.FindViewById(Resource.Id.tvIdShow);
                //id.SetText(c.GetString(0), TextView.BufferType.Normal);
                //time.SetText(c.GetString(1), TextView.BufferType.Normal);
                //String daTag = c.GetString(1);
                //Button delButton = (Button)view.FindViewById(Resource.Id.delButton);
                //delButton.Focusable = true;
                //delButton.Clickable = true;
                //delButton.Click += new EventHandler(delButton_Click);
                //Context tt = context;
                //ICursor cc = cursor;
                //idS = cc.GetInt(cc.GetColumnIndex("_id"));
                idS = Convert.ToInt32(cursor.GetString(0));
            void delButton_Click(object sender, EventArgs e)
                //Android.Widget.Toast.MakeText(this, ex.StackTrace, Android.Widget.ToastLength.Short).Show();
                AlertDialog alertDialog = new AlertDialog.Builder(context).Create();
                // Setting Dialog Title
                alertDialog.SetTitle("Alert Dialog");
                // Setting Dialog Message
                alertDialog.SetMessage("Delete ID : " + idS.ToString());


  • alinjojobaalinjojoba INMember ✭✭

    but now the problem is :
    How to get the row id selected !
    my code return wrong id;

    idS = Convert.ToInt32(cursor.GetString(0));

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    Why don't you do what the java code does. It gets the index of the "_id" column, and then gets that column as an integer.

    idS = cursor.GetInt(cursor.GetColumnIndex("_id"));

    I'm assuming that your call "cursor.GetString(0)" is not the correct index for the column your looking for.

  • alinjojobaalinjojoba INMember ✭✭

    no use!!!!!!!!!!!!!

  • rmaciasrmacias USBeta, University ✭✭✭✭✭

    Alright, we can't help unless you explicitly state what your problem is exactly. You have not clearly defined what the issue is and the measures you have take to try to resolve the issue. Until you do that, it is unlikely someone will be able to help.

  • StevenTheEvenStevenTheEven SEMember ✭✭✭

    What? Can you please try to write full sentences so people will have a chance to understand and have at least a little chance to help you? We do this for free on our spare time so be polite.
    idS = c.GetInt(c.GetColumnIndex("_id"));

  • alinjojobaalinjojoba INMember ✭✭

    thanks all for reply!
    i wanna to have listview with delete button.and when the delete button clicked it should show Id and ask :
    do you wanna delete this row? Yes,No
    How to do that !!!!!!!!!

  • FZelleFZelle DEMember ✭✭✭

    By putting the ID ( that you have in GetView ) into the Tag and use it in the ButtonClick.

  • alinjojobaalinjojoba INMember ✭✭

    how can i do that?
    Can give me example???

  • alinjojobaalinjojoba INMember ✭✭

    Done That!
    Thanks all for help!

  • alinjojobaalinjojoba INMember ✭✭

    now after doing all now i cannt scroll horizontal for listview !!!!!!

  • alinjojobaalinjojoba INMember ✭✭

    please HELP!!!!!!!!!!!!!!!

    NO One is THERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sign In or Register to comment.