Android notifyDataSetChanged()未刷新listview

Android notifyDataSetChanged()未刷新listview,android,listview,adapter,notifydatasetchanged,Android,Listview,Adapter,Notifydatasetchanged,这是我的适配器: public class Conversa extends BaseAdapter { private Context context; private ArrayList<String> log; private String target; public Conversa(Context context, String target) { this.context = context; this.target = target;

这是我的适配器:

    public class Conversa extends BaseAdapter {

private Context context;
private ArrayList<String> log;
private String target;

public Conversa(Context context, String target) {
    this.context = context;
    this.target = target;
    log = new ArrayList<String>();
}

@Override
public int getCount() {
    return log.size();
}

@Override
public Object getItem(int pos) {
    return log.get(pos);
}

@Override
public long getItemId(int arg0) {
    return 0;
}

@Override
public View getView(int pos, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.msg_layout, parent, false);
    }

    TextView msg = (TextView) convertView.findViewById(R.id.msg);
    msg.setText(log.get(pos));

    return convertView;
}

public ArrayList<String> getLog() {
    return log;
}

public String getTarget() {
    return target;
}

public void setTarget(String target) {
    this.target = target;
}

public void addMessage(String msg) {
    log.add(msg);
    notifyDataSetChanged();
}
  }
如果我收到聊天信息,它不会出现在列表中,尽管该信息会出现在日志中。当我触摸edittext编写消息时,它刷新视图并显示消息。 我希望它一出现就出现。 请帮帮我。

拆下

public void addMessage(String msg) {
log.add(msg);
notifyDataSetChanged();
并将其用于您的主要活动:

Conversa.log.add(msg);
notifyDataSetChanged();

必须从UI线程调用notifyDataSetChanged。@Matheus Henrique da Silva如果答案有用,请接受或/并向上投票:-))我的notifyDataSetChanged()正在守护进程线程上运行,我如何使它在UI线程上运行?它可以用于服务?这就是我需要的。
Conversa.log.add(msg);
notifyDataSetChanged();