I have a list view of Hotels and I want when the user clicks a long click on an item a dialog appears with the information of the clicked hotel retrieved from the SQLite database (Location, Address, Phone number...etc.). I retrieve data from the database in a List. In the dialog message when I convert the list toString() the result has extra square brackets, example: Phone: [02239348], what should I do? Is there another way?
Here is the code from DataSource.java which retrieves the location from database:
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;
}
Here is the alert dialog:
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;
}