我有一个酒店的列表视图,我希望当用户长按某个项目时,会出现一个对话框,其中包含从 SQLite 数据库中检索到的所点击酒店的信息(位置、地址、电话号码等)。我从列表中的数据库中检索数据。在我将列表转换为 toString() 时的对话框消息中,结果有多余的方括号,例如:电话:[02239348],我该怎么办?还有其他方法吗?
这是 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;
}