0

データベースからリストビューにいくつかの要素を入れようとしていますが、私の問題は、アクティビティを開始すると、次のようになることです:

**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);

            }
        });


    }

}
4

1 に答える 1

0

レストランの名前のリストを表示したい場合、Restaurant クラスに文字列属性「name」が含まれていると仮定すると、最初にレストランの名前を含む配列を作成し、次に を使用する必要がありますArrayAdapter <String>

String[] values = new String[restaurantlist.size()];
for(int i=0;i<restaurantlist.size();i++) {
    values[i] = restaurantlist.get(i).getName();
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
listview.setAdapter(adapter);
于 2013-07-28T00:28:11.487 に答える