search

Home  >  Q&A  >  body text

android - Binary XML file line #32: Error inflating class TextView???

PHP中文网PHP中文网2772 days ago632

reply all(2)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 16:53:04

    This is whether there is a problem in parsing XML出现了问题,建议Rebuild一下刷新XML布局文件,另外检查一下布局文件中的XCRoundImageView.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 16:53:04

    I looked at your code carefully and found that the error is probably caused by this reason.
    Let me first talk about the intention of your code and see if it is correct:
    You want to display the information you receive and the information you send in the chat interface, but the arrangement of these information is irregular.
    Your idea of ​​using two ViewHolders to save the received information and the content in the layout file corresponding to the information sent by yourself is correct. Let’s take a look at this code of yours

     if (convertView == null) {
                if (getItemViewType(position) == 0) {
                    convertView = mInflater.inflate(R.layout.item_chat_receivemsg, parent, false);
                    viewHolder = new ViewHolder();
                    viewHolder.mDate = (TextView) convertView
                            .findViewById(R.id.tv_from_time);
                    viewHolder.mMsg = (TextView) convertView
                            .findViewById(R.id.tv_from_content);
                } else {
                    convertView = mInflater.inflate(R.layout.item_chat_sendmsg, parent, false);
                    viewHolder = new ViewHolder();
                    viewHolder.mDate = (TextView) convertView
                            .findViewById(R.id.tv_to_time);
                    viewHolder.mMsg = (TextView) convertView
                            .findViewById(R.id.tv_to_content);
                }
                convertView.setTag(viewHolder);
            }

    Obviously, your code will only save one ViewHolder, and usually it will save the ViewHolder that accepts information, because the code statement in if (convertView == null) will only Execute once. if (convertView == null)里面的代码语句在一开始时只会执行一次。

    给你一个解决方案的思路:

    • 用两个convertView和ViewHolder保存分别保存接受到的信息和自己发送的信息

    • 在ChatMessageBean里面添加一个判断是发送信息还是接受信息的字段

    • getView中根据ChatMessageBean chatMessageBean = messageBeans.get(position);

      Give you an idea of ​​a solution:
      Use two convertView and ViewHolder to save the received information and the information sent by yourself respectively🎜🎜
    • 🎜Add a field in ChatMessageBean to determine whether to send or receive information🎜🎜
    • 🎜In getView, determine whether to send or receive information based on the new field in ChatMessageBean chatMessageBean = messageBeans.get(position);, and then check the corresponding ViewHolder processes it and returns the corresponding convertView🎜🎜 🎜

      reply
      0
  • Cancelreply