设置复选框,如果db表值xamarin.android 1 [英] set the checkbox if the db table value is 1 in xamarin.android

查看:111
本文介绍了设置复选框,如果db表值xamarin.android 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查该编辑code ..它的工作,但没有显示越来越打勾,但其他两列R丝网印刷id和date..Not得到什么错在我setviewvalue方法database..check框的数据。

 保护覆盖无效的OnCreate(束SaveInstace)
        {
            base.OnCreate(SaveInstace);
            的setContentView(Resource.Layout.ListView_layout);
            ActionBar.SetDisplayHomeAsUpEnabled(真);
            //获取ListView的对象实例
            数据库sqldb1 =((GlobalClass)this.Application).sqldb;
            时listItems = FindViewById<&的ListView GT; (Resource.Id.listItems);            GetCursorView();
        }        无效GetCursorView()
        {
            数据库sqldb1 =((GlobalClass)this.Application).sqldb;
            Android.Database.ICursor sqldb_cursor = sqldb1.GetRecordCursor();
            如果(sqldb_cursor!= NULL)
            {
                sqldb_cursor.MoveToFirst();
                字符串[] =由新的字符串[] {_id,日期,值};
                INT []为= INT新[] {
                    Resource.Id.ListRow1,
                    Resource.Id.ListRow2,
                    Resource.Id.ListRow3                };
                    //创建用于ListView控件对象的SimplecursorAdapter
                SimpleCursorAdapter sqldb_adapter =新SimpleCursorAdapter(这一点,Resource.Layout.record_view,sqldb_cursor,从,到);
                sqldb_adapter.ViewBinder =新MyCustomView();                listItems.Adapter = sqldb_adapter;
            }
            其他
            {            }
        }        公共类MyCustomView:java.lang.Object中,SimpleCursorAdapter.IViewBinder
        {            公共BOOL SetViewValue(查看视图,Android.Database.ICursor光标,int i)以
            {
                如果(view.Id == Resource.Id.ListRow3)                {
                    //如果列IS_STAR然后我们用自定义视图。
                    INT is_val = cursor.GetInt(ⅰ);
                    复选框CB =(复选框)视图。
                    如果(is_val!= 0)
                    {
                        //设置视图GONE的知名度                        cb.Checked = TRUE;
                        返回true;
                }
                    其他
                {
                    返回true;
                }
                //对于其他人,我们简单地返回false,这样的默认绑定
                //发生。            }
                返回true;
       }
    }


解决方案

这code奋力我要感谢你... :)

 公共类MyCustomView:java.lang.Object中,SimpleCursorAdapter.IViewBinder
            {                公共BOOL SetViewValue(查看视图,Android.Database.ICursor光标,int i)以
                {
                    如果(view.Id == Resource.Id.ListRow1){
                        INT VAL = cursor.GetInt(ⅰ);
                        TextView的TXT =(TextView的)视图。
                        txt.Text = val.ToString();
                    }
                    如果(view.Id == Resource.Id.ListRow2){
                        串val1中= cursor.GetString(ⅰ);
                        TextView的TXT =(TextView的)视图。
                        txt.Text = VAL1;
                    }
                    如果(view.Id == Resource.Id.ListRow3)                    {
                        //如果列IS_STAR然后我们用自定义视图。
                        INT is_val = cursor.GetInt(ⅰ);
                        复选框CB =(复选框)视图。
                        如果(is_val!= 0)
                        {
                            //设置视图GONE的知名度                            cb.Checked = TRUE;
                            返回true;
                    }
                        其他
                    {
                            cb.Clickable = FALSE;
                        返回true;
                    }
                    //对于其他人,我们简单地返回false,这样的默认绑定
                    //发生。                }
                    返回true;
           }

Please check this edited code.. its working but not showing the data of database..check box is getting tick but other 2 columns r printing as id and date..Not getting whats wrong in my setviewvalue method..

protected override void OnCreate (Bundle SaveInstace)
        {
            base.OnCreate (SaveInstace);
            SetContentView (Resource.Layout.ListView_layout);
            ActionBar.SetDisplayHomeAsUpEnabled (true);
            //Gets ListView object instance
            Database sqldb1 = ((GlobalClass)this.Application).sqldb;
            listItems = FindViewById<ListView> (Resource.Id.listItems);

            GetCursorView ();
        }

        void GetCursorView()
        {
            Database sqldb1 = ((GlobalClass)this.Application).sqldb;
            Android.Database.ICursor sqldb_cursor = sqldb1.GetRecordCursor();
            if (sqldb_cursor != null) 
            {
                sqldb_cursor.MoveToFirst ();
                string[] from = new string[] {"_id","date","Value"};
                int[] to = new int[] {
                    Resource.Id.ListRow1,
                    Resource.Id.ListRow2,
                    Resource.Id.ListRow3

                };
                    //Creates a SimplecursorAdapter for ListView object
                SimpleCursorAdapter sqldb_adapter = new SimpleCursorAdapter (this, Resource.Layout.record_view, sqldb_cursor, from, to);
                sqldb_adapter.ViewBinder = new MyCustomView();

                listItems.Adapter = sqldb_adapter;
            } 
            else 
            {

            }
        }

        public class MyCustomView:Java.Lang.Object, SimpleCursorAdapter.IViewBinder
        {

            public bool SetViewValue (View view, Android.Database.ICursor cursor, int i)
            {
                if (view.Id == Resource.Id.ListRow3) 

                { 
                    // If the column is IS_STAR then we use custom view.
                    int is_val = cursor.GetInt (i);
                    CheckBox cb = (CheckBox) view;
                    if (is_val != 0)
                    {
                        // set the visibility of the view to GONE

                        cb.Checked = true;
                        return true;
                } 
                    else
                {
                    return true;
                }
                // For others, we simply return false so that the default binding
                // happens.

            }
                return true;
       }
    }

解决方案

this code worked me thank you...:)

public class MyCustomView:Java.Lang.Object, SimpleCursorAdapter.IViewBinder
            {

                public bool SetViewValue (View view, Android.Database.ICursor cursor, int i)
                {
                    if (view.Id == Resource.Id.ListRow1) {
                        int val = cursor.GetInt (i);
                        TextView txt = (TextView)view;
                        txt.Text = val.ToString ();
                    }
                    if (view.Id == Resource.Id.ListRow2) {
                        string val1 = cursor.GetString (i);
                        TextView txt = (TextView)view;
                        txt.Text = val1;
                    }
                    if (view.Id == Resource.Id.ListRow3) 

                    { 
                        // If the column is IS_STAR then we use custom view.
                        int is_val = cursor.GetInt (i);
                        CheckBox cb = (CheckBox) view;
                        if (is_val != 0)
                        {
                            // set the visibility of the view to GONE

                            cb.Checked = true;
                            return true;
                    } 
                        else
                    {
                            cb.Clickable = false;
                        return true;
                    }
                    // For others, we simply return false so that the default binding
                    // happens.

                }
                    return true;
           }

这篇关于设置复选框,如果db表值xamarin.android 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆