sqlite Viewlist错误

时间:2013-07-27 23:30:42

标签: android sqlite android-listview

我尝试将数据库中的一些元素放到List视图中, 我的问题是,当我主演我的活动时,我明白了:

** com.example.restaurant.Restaurant@2be2d1d0

com.example.restaurant.Restaurant@2be3d3a8 **

而不是数据库对象。

public class Liste extends Activity{

    private ListView listview;
    private Button boutonAjouter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.liste_restaurant);

        listview = (ListView)findViewById(R.id.listView1);

        Restaurant mcdo = new Restaurant("mcdo","brossard","take-out","fastfood","450-555-5555");
        Restaurant burger = new Restaurant("burger","longueuil","take-out","fastfood","450-999-9999");

        RestaurantBDD restaurantBDD = new RestaurantBDD(this);
        restaurantBDD.openForWrite();
        restaurantBDD.insertRestaurant(mcdo);
        restaurantBDD.insertRestaurant(burger);

        ArrayList <Restaurant> restaurantlist = restaurantBDD.getAllRestaurants();
        restaurantBDD.close();

        ArrayAdapter <Restaurant> adapter = new ArrayAdapter<Restaurant>(this, android.R.layout.simple_list_item_1, restaurantlist);
        listview.setAdapter(adapter);


        boutonAjouter = (Button) findViewById(R.id.btn_nouveau);
        boutonAjouter.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Liste.this, Formulaire.class);
                startActivity(intent);

            }
        });


    }

}

1 个答案:

答案 0 :(得分:0)

如果要显示包含餐馆名称的列表,假设您的Restaurant类包含字符串属性“name”,则应首先创建一个包含餐馆名称的数组,然后使用{{1} }:

ArrayAdapter <String>