Android hashmap显示不完整的值

时间:2015-11-02 08:15:05

标签: java android

大家好,我在显示地图值时遇到问题。这是我的代码:

CustomAdapter:

Map<String, List<Show>> map;
List<Map.Entry<String, List<Show>>> list;

public WorldShowsAdapter(Context context,
                         Map<String, List<Show>> map) {
    this.context = context;
    this.map = map;
    list = new ArrayList(map.entrySet());
}

@Override
public Map.Entry<String, List<WorldShow>> getItem(int position) {
    return list.get(position);
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

 final ViewHolder viewHolder;

    if(convertView == null) {

        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = inflater.inflate(R.layout.list_show_item, parent, false);

        viewHolder = new ViewHolder();
        viewHolder.tvShowName = (TextView) convertView.findViewById(R.id.tvShowName);
        viewHolder.tvShowName2 = (TextView) convertView.findViewById(R.id.tvShowName2);
        viewHolder.btViewAllShows = (MyButton) convertView.findViewById(R.id.btViewAllShows);
        viewHolder.rvShows = (RecyclerView) convertView.findViewById(R.id.rvShows);
        viewHolder.llBackground = (LinearLayout) convertView.findViewById(R.id.llBackground);
        viewHolder.showsManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        viewHolder.rvWorldShows.setLayoutManager(viewHolder.showsManager);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

 Map.Entry<String, List<Show>> entry = this.getItem(position);
    viewHolder.tvShowName.setText(entry.getKey());

    List<Show> shows = entry.getValue();

    for (Show s: shows) {
        viewHolder.tvShowName2.setText(s.getShowTitle());
    }
}


private void display(RecyclerView rvWorldShows,
                     Map<String, List<WorldShow>> catShows,
                     List<WorldShow> showData) {

    WorldDetailsShowsRecyclerViewAdapter showsAdapter
            = new WorldDetailsShowsRecyclerViewAdapter(context, catShows, showData);

    if(showsAdapter.getItemCount() > 0) {
        rvShows.setVisibility(View.VISIBLE);
        rvShows.setAdapter(showsAdapter);
    } else {
        rvShows.setVisibility(View.GONE);
    }

}

我只是得到了最后一个值。

当我改为:

   viewHolder.tvShowName2.setText(entry.getValue().toString());

它显示了这个:

[Talk=[
com.test.models.Show@fe6eb61, 
com.test.models.Show@f0ff686, 
com.test.models.Show@88cfb47]

为什么我会得到这些?我很感激任何帮助。谢谢!

2 个答案:

答案 0 :(得分:0)

  

为什么我会得到这些?我很感激任何帮助。谢谢!

[Talk=[
com.test.models.Show@fe6eb61, 
com.test.models.Show@f0ff686, 
com.test.models.Show@88cfb47]

toString()的{​​{1}},而List<Show>com.test.models.Show@fe6eb61的{​​{1}}。如果您在toString()中覆盖Show,并返回有意义的内容,您将获得类似

的内容
toString()

您可能希望使用Show,而不是简单的[Talk=[ "aaa", "bbb", "ccc"] ,其中ExpandableListView是您的HashMap的关键,ListView是群组的子项

答案 1 :(得分:0)

而不是使用setText使用TextView的append方法在单个TextView中显示所有数据:

for (WorldShow s: shows) {
        viewHolder.tvShowName2.append(s.getShowTitle()+"\n");
    }