4

ListView にデータベース アイテムを設定できません。

テーブルを取得するためのsqliteの関数:

public Android.Database.ICursor getFornecedores()
        {
            Android.Database.ICursor temp = null;
            try
            {
                sqlQuery = "SELECT * FROM Fornecedor;";
                temp = sqlTemp.RawQuery(sqlQuery, null);
                if (!(temp != null))
                    Console.WriteLine("Deu pau");
            }
            catch(SQLiteException e)
            {
                Console.WriteLine("Erro = " + e.Message);
            }
            return temp;
        }

機能 listView にデータを入力してみます:

public void loadListView()
        {
            Android.Database.ICursor fornecedores;
            DataBaseHandler db = new DataBaseHandler();
            fornecedores = db.getFornecedores();
            SimpleCursorAdapter adapter;

            cadastroListView.Adapter = new SimpleCursorAdapter(this, Android.Resource.Layout.SimpleDropDownItem1Line, fornecedores,
                                        new string[] { "nome" }, new int[] { Android.Resource.Id.Text1 });


        }

お願い助けて!ありがとう!

4

1 に答える 1

0
        List<string> mItems = new List<string>();
        var listview = FindViewById<ListView>(Resource.Id.listview);

 //fetching data from database. I am using sqlite.cs to fetch data from database.
 //You can use your technique which you are using.

        using (var conn = new SQLite.SQLiteConnection(dbPath))
        {
            try
            {
                var cmd = new SQLite.SQLiteCommand(conn);
                cmd.CommandText = "select * from history";
                int i = 0;
                var r = cmd.ExecuteQuery<hist>();
                foreach (var item in r)
                {
                    mItems.Add(item.word);
                }

            }
            catch (Exception e)
            {

            }
        }

        ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, mItems);

        listview.Adapter = adapter;
于 2017-07-10T16:52:06.950 に答える