Hi, I am populating my listview from Sqlite (sometime also from DataTable) 1. when the data is huge its very slow ? 2. how to have filter for this with high speed ?(same as contact list )
Thanks in advanced ! For filtering i have seen this code :
_adapter.Filter.InvokeFilter(_inputSearch.Text);
but just work for one column :
_adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, Resource.Id.product_name, products);
No USE At ALL !!!!
my code :
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create your application here SetContentView(Resource.Layout.HesabList); progress = ProgressDialog.Show(this, "", "Loading ..."); progress.SetProgressStyle(ProgressDialogStyle.Spinner); progress.Indeterminate = true; new Thread(new ThreadStart(delegate { _btnUpdate = FindViewById<Button>(Resource.Id.UpdateHesabList); _btnUpdate.Click += new EventHandler(_btnUpdate_Click); gvHesab = FindViewById<ListView>(Resource.Id.gvHesabList); gvHesab.ItemClick += new EventHandler<AdapterView.ItemClickEventArgs>(gvHesab_ItemClick); isTarafHesab = Intent.GetBooleanExtra("IsTarafHesab", false); txtSearchHesabList = (EditText)FindViewById(Resource.Id.txtSearchHesabList); txtSearchHesabList.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs>(txtSearchHesabList_TextChanged); txtSearchHesabList.Gravity = GravityFlags.Right; Looper.Prepare(); File dbtest = new File(clsBase.SqliteDBPath); if (!dbtest.Exists() ) { if (clsBase.HasInternetConnection(this)) createDbSqlite(); else { MessageBoxAndroid.Show(this, "Connect to Internet First !"); Finish(); } } else { fillListView(); } RunOnUiThread(() => progress.Dismiss()); })).Start(); }
private void fillGridView() { try { SQLiteDatabase db = OpenOrCreateDatabase("test.db", FileCreationMode.WorldReadable, null); ICursor cursors = db.RawQuery("select Moen, Hesab, opab, Coab,(select count(*) from tbl_Hest b where a._id >= b._id) as _id,Id from tbl_Hest a", null); String[] from = Resources.GetStringArray(Resource.Array.gvHesabHeader); int[] to = { Resource.Id.txt_HesabListGrid_Heen, Resource.Id.txt_HesabListGrid_Heol ,Resource.Id.txt_HesabListGrid_Heb, Resource.Id.txt_HesabListGrid_Coab,Resource.Id.txt_HesabListGrid_Row,Resource.Id.txt_HesabListGrid_Id}; RunOnUiThread(() => { SimpleCursorAdapter _HesabGridAdapter = new HesabListGridview(this, Resource.Layout.HesabListGrid, cursors, from, to); gvHesab.Adapter = _HesabGridAdapter; }); setListViewHeightBasedOnChildren(gvHesab);//بخورد Scroll برای حالتی که کل صفحه gvHesab.TextFilterEnabled = true; EditText txtSearchHesabList = (EditText)FindViewById(Resource.Id.txtSearchHesabList); txtSearchHesabList.TextChanged += new EventHandler<Android.Text.TextChangedEventArgs> (txtSearchHesabList_TextChanged); } catch (Exception ex) { } }
class HesabListGridview : SimpleCursorAdapter { ICursor c; //MatrixCursor cur; Context context; Activity activity; int idS; public HesabListGridview(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; } bool isFirst = true; public static int dtRowCount = 0; int CountRepeated = 0; public override Filter Filter { get { return base.Filter; } } public override IFilterQueryProvider FilterQueryProvider { get { return base.FilterQueryProvider; } set { base.FilterQueryProvider = value; } } public override View GetView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = View.Inflate(context, Resource.Layout.HesabListGrid, null); View row = convertView; try { c.MoveToPosition(position); TextView txtHesabGrid_Coni = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Hesoen); TextView txtHesabGrid_Bde = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Hesol); TextView txtHesabGrid_Nab = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Heab); TextView txtHesabGrid_Cosab = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Coab); TextView txtHesabGrid_Row = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Row); TextView txtHesabGrid_Id = (TextView)convertView.FindViewById(Resource.Id.txt_HesabListGrid_Id); txtHesabGrid_Coni.SetText(c.GetString(c.GetColumnIndex("Hen")), TextView.BufferType.Normal); txtHesabGrid_Bde.SetText(c.GetString(c.GetColumnIndex("Hl")), TextView.BufferType.Normal); txtHesabGrid_Nab.SetText(c.GetString(c.GetColumnIndex("Heb")), TextView.BufferType.Normal); txtHesabGrid_Cosab.SetText(c.GetString(c.GetColumnIndex("Coab")), TextView.BufferType.Normal); txtHesabGrid_Row.SetText(c.GetInt(c.GetColumnIndex("_id")).ToString(), TextView.BufferType.Normal); txtHesabGrid_Id.SetText(c.GetString(c.GetColumnIndex("Id")), TextView.BufferType.Normal); txtHesabGrid_Id.Visibility = ViewStates.Gone; //txtHesabGrid_Id.Visibility = ViewStates.Invisible; if (position % 2 == 0) { convertView.SetBackgroundColor(Android.Graphics.Color.ParseColor("#6bcdfb")); } else { convertView.SetBackgroundColor(Android.Graphics.Color.ParseColor("#2cb8de")); } CountRepeated++; // MessageBoxAndroid.Show(context, CountRepeated.ToString() + "\n" + dtRowCount.ToString()); if (17 == CountRepeated) { isFirst = false; } if (isFirst) { HorizontalScrollView hv = (HorizontalScrollView)activity.FindViewById(Resource.Id.scrollHesabListGrid); hv.FullScroll(FocusSearchDirection.Left); } } catch (Exception ex) { } //hv.ScrollTo(hv.Right + 80, hv.Top); return (row); } } }