将类似的项目分组

时间:2013-03-27 09:14:58

标签: android

我从webservice获取解析后的响应,如下所示

<Table>
    <Restaurant_ID>2153</Restaurant_ID>
    <restaurant_name>Bhagini Palace</restaurant_name>
    <address>210, 1st Main, 'A' Cross, ESI Hospital Road, 2nd Stage, Domlur, Bangalore</address>
    <costoftwo>Approx Rs. 400 for two (without alcohol)</costoftwo>
    <rating>2.6</rating>
    <timings>11:30 AM to 4 PM, 6:30 PM to 11 PM</timings>
    <Phone>08040799999,+919731323333</Phone>
    <Location_ID>53</Location_ID>
    <Location_name>Domlur</Location_name>
    <city_ID>1</city_ID>
    <city_name>Bangalore</city_name>
    <Cuisine_ID>8</Cuisine_ID>
    <Cuisine_name>North Indian</Cuisine_name>
  </Table>
  <Table>
    <Restaurant_ID>2153</Restaurant_ID>
    <restaurant_name>Bhagini Palace</restaurant_name>
    <address>210, 1st Main, 'A' Cross, ESI Hospital Road, 2nd Stage, Domlur, Bangalore</address>
    <costoftwo>Approx Rs. 400 for two (without alcohol)</costoftwo>
    <rating>2.6</rating>
    <timings>11:30 AM to 4 PM, 6:30 PM to 11 PM</timings>
    <Phone>08040799999,+919731323333</Phone>
    <Location_ID>53</Location_ID>
    <Location_name>Domlur</Location_name>
    <city_ID>1</city_ID>
    <city_name>Bangalore</city_name>
    <Cuisine_ID>13</Cuisine_ID>
    <Cuisine_name>Chinese</Cuisine_name>
  </Table>
  <Table>
    <Restaurant_ID>2153</Restaurant_ID>
    <restaurant_name>Bhagini Palace</restaurant_name>
    <address>210, 1st Main, 'A' Cross, ESI Hospital Road, 2nd Stage, Domlur, Bangalore</address>
    <costoftwo>Approx Rs. 400 for two (without alcohol)</costoftwo>
    <rating>2.6</rating>
    <timings>11:30 AM to 4 PM, 6:30 PM to 11 PM</timings>
    <Phone>08040799999,+919731323333</Phone>
    <Location_ID>53</Location_ID>
    <Location_name>Domlur</Location_name>
    <city_ID>1</city_ID>
    <city_name>Bangalore</city_name>
    <Cuisine_ID>26</Cuisine_ID>
    <Cuisine_name>Andhra</Cuisine_name>
  </Table>

我使用customadapter显示restaurant_name和菜单在listview中

holder.txtvalue.setText(mlist.get(position)
                        .getRestaurant_name()
                        + "\n"
                        + mlist.get(position).getCuisine_name());

但是当餐馆ID相同时,我想将菜肴名称分组并需要在列表视图中显示。

我尝试过这样的事情

cuisines = mlist.get(position).getCuisine_name();

                Integer id = mlist.get(position).getRestaurant_ID();
                Log.d("restaurant_id", ""+id);
                for (int i = 1; i < 10; i++) {

                    if (id.equals(mlist.get(position+i).getRestaurant_ID())) {

                        if(id.equals(mlist.get(position+(i+1)).getRestaurant_ID())){

                            cuisines = cuisines +","+ mlist.get(position+i).getCuisine_name()
                                    +","+ mlist.get(position+(i+1)).getCuisine_name();  
                        }else

                        cuisines = cuisines +","+ mlist.get(position+i).getCuisine_name();
                        Log.d("cuisiene_id", ""+cuisines);
                    }
                }
                holder.txtvalue.setText(mlist.get(position)
                        .getRestaurant_name() + "\n" + cuisines);

但我会在团体和个人中获得美食名称。

我怎样才能避免显示个人?

感谢:)

1 个答案:

答案 0 :(得分:0)

使用可扩展列表视图。根据餐馆ID填充组视图,子视图可以是餐厅中的每个项目。看看那里的the tutorials可以做到这一点。

expandable list view