我正在我的應用中實現聊天泡泡。在主類中,我在下面提到的私有類「mylistadapter」的setText行中出現錯誤。我在實現Android聊天泡泡時遇到錯誤
tekst.setText(bubbleGreen.getMessages()); <-- line I am getting error
錯誤消息是: 在類型TextView的方法的setText(CharSequence的)是不適用的參數(ArrayList的)
在我已經使用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));
}
你的適配器應該由字符串而不是氣泡組成,數據集應該是bubbles.getMessages(),或者你應該改變你的Bubbles類的概念。從一個消息容器它將是一個消息,然後它應該工作 – Blackbelt
你好,我現在有兩個不同的建議。檢出他們兩個。謝謝你的建議 – Sindre