私はホテルのリストビューを持っています。ユーザーがアイテムの長いクリックをクリックすると、SQLiteデータベースから取得したクリックされたホテルの情報を含むダイアログが表示されます(場所、住所、電話番号数字など...)。 リスト内のデータベースからデータを取得します。 ダイアログメッセージで、リストをtoString()に変換すると、結果に余分な角括弧(例:Phone:[02239348])が表示されます。どうすればよいですか?別の方法がありますか?ここでSQLiteデータベースのデータを使用したダイアログ
は、データベースから場所を取得DataSource.javaからのコードです:ここでは
public List<Hotel> getHotelLocation(String hotelName) {
List<Hotel> hotels = new ArrayList<Hotel>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_Hotel,
hotelsLoc, hotelsNames[0] + " like " + "'" + hotelName + "'", null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Hotel hotel = cursorToHotel(cursor);
hotels.add(hotel);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return hotels;
}
private Hotel cursorToHotel(Cursor cursor) {
// TODO Auto-generated method stub
Hotel hotelname = new Hotel();
hotelname.setName(cursor.getString(0));
return hotelname;
}
は警告ダイアログです:
public boolean onItemLongClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
String hotelName = (String) ((TextView)parent.getChildAt(position)).getText();
List<Hotel> location = datasource.getHotelLocation(hotelName);
String loc = "Location: " + location.toString();
List<Hotel> address = datasource.getHotelAddress(hotelName);
String add = "Address: " + address.toString();
List<Hotel> rating = datasource.getHotelRating(hotelName);
String rat = "Rating: " + rating.toString();
List<Hotel> phone = datasource.getHotelPhone(hotelName);
String phoneN = "Phone: " + phone.toString();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Information about " + hotelName);
builder.setMessage(loc + "\n" + add + "\n" + rat + "\n" + phoneN + "\n");
builder.setCancelable(true);
builder.show();
return false;
}
を使用することができ、あなたのホテルクラスのtoString()をオーバーライドしますか?私は変更する部分を知らない – MahaK
あなたのホテルクラスのソースを投稿してください。私はgetHotelPhoneメソッドが何をしているのか見たいと思います。 – twaddington
公開リスト getHotelPhone(文字列ホテル名){ \t \tリストホテル=新しいArrayList (); \t \tカーソルカーソル= database.query(MySQLiteHelper.TABLE_Hotel、 \t \t \t \t hotelsPhone、hotelsNames [0] + "のような" + " '" + hotelName + "'"、NULL、NULL、NULL、NULL); \t \t cursor.moveToFirst(); \t \tしばらく{ \t \t \tホテルホテル= cursorToHotel(カーソル)(cursor.isAfterLast()!)。 \t \t \t hotels.add(ホテル); \t \t \t cursor.moveToNext(); \t \t} \t \t // \t \t cursor.close(カーソルをクローズすることを確認してください)。 \t \t戻るホテル; \t} –
MahaK