Arraylist没有在listview android中打印

时间:2015-01-14 15:53:32

标签: java android listview arraylist

我正在尝试在listview中打印来自db的arraylist,但它不在列表视图中打印它。 请检查代码并标出我的错误。

listView = (ListView) findViewById(R.id.list);

        loginDataBaseAdapter=new LoginDataBaseAdapter(this);
         loginDataBaseAdapter=loginDataBaseAdapter.open();
         List<Info> contacts = loginDataBaseAdapter.getAll();
         for (Info cn : contacts) {

                String log = "Id: "+cn.getUsername()+" ,Name: " + cn.getPassword() + " ,Phone: " + cn.getPlacespend();
               /* view1.setText("Your name is: " + cn.getUsername());
                view2.setText("Your place of spenditure is: " + cn.getPlacespend());
                view3.setText("Your amount of spenditure is: " + cn.getAmountspend());
                    // Writing Contacts to log
                     * */

            Log.d("Name: ", log);
    }
         ArrayAdapter<Info> adapter = new ArrayAdapter<Info>(this,
                  android.R.layout.simple_list_item_1,contacts);
         listView.setAdapter(adapter); 

数据库功能

public List<Info> getAll()
        {
            List<Info> infolist = new ArrayList<Info>();
            Cursor cursor=db.query("LOGIN2", null, null, null, null, null, null, null);
            if (cursor.moveToFirst()) {
                do {
                    Info contact = new Info();
                    contact.setUsername(cursor.getString(1));
                    contact.setPassword(cursor.getString(2));
                    contact.setPlacespend(cursor.getString(3));
                    contact.setAmountspend(cursor.getString(4));

                    // Adding contact to list
                    infolist.add(contact);
                } while (cursor.moveToNext());
            }
            cursor.close();
            return infolist;                
        }

0 个答案:

没有答案