我在实现Android Chat Bubbles时遇到错误

时间:2014-02-18 09:38:05

标签: java android arraylist

我正在我的应用中实现聊天气泡。在主类中,我在下面提到的私有类“mylistadapter”中的setText行中收到错误。

tekst.setText(bubbleGreen.getMessages()); <-- line I am getting error

错误消息是: TextView类型中的方法setText(CharSequence)不适用于参数(ArrayList)

在Bubbles类中,我使用了ArrayListgetMessages。我不知道如何在使用ArrayList时修复此错误。任何提示都会非常感激。谢谢。

泡泡类:

import java.util.ArrayList;
public class Bubbles {

private ArrayList<String> messages;
private int ikonId;

public Bubbles(ArrayList<String> messages, int ikonId){
    super();
    this.messages = messages;
    this.ikonId=ikonId;
}

public ArrayList<String> getMessages(){
    return messages;
}

public int getIkonId(){
    return ikonId;
}


}

主类:

private void setListAdapter() {
    // TODO Auto-generated method stub
    ArrayAdapter<Bubbles> adapter = new MyListAdapter();
    ListView list = (ListView) findViewById(R.id.listMessages);
    list.setAdapter(adapter);

}

private class MyListAdapter extends ArrayAdapter<Bubbles> {
    public MyListAdapter() {
        super(XMPPChatDemoActivity.this, R.layout.list_row_layout_even, bubbles);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View itemView = convertView;
        if (itemView == null) {
            itemView = getLayoutInflater().inflate(
                    R.layout.list_row_layout_even, parent, false);
        }


        Bubbles bubbleGreen = bubbles.get(position);


        ImageView imageView = (ImageView) itemView
                .findViewById(R.id.even_bubble);
        imageView.setImageResource(bubbleGreen.getIkonId());

        TextView tekst = (TextView) itemView.findViewById(R.id.text01);
        <<<tekst.setText(bubbleGreen.getMessages());>>>

        return itemView;
    }
}

private void bubblesList() {
    // TODO Auto-generated method stub
    bubbles.add(new Bubbles(messages, R.drawable.bubble_green));
}

1 个答案:

答案 0 :(得分:2)

替换

tekst.setText(bubbleGreen.getMessages());

tekst.setText(bubbleGreen.getMessages().get(position));

并且错误本身显示问题是什么。