当我点击列表视图上的按钮时,我在另一个列表视图中使用列表视图我必须将项目添加到内部列表视图。如何调用内部listview适配器的notifydatasetchanged。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.homeinnernew1, parent, false);
holder = new ViewHolder();
holder.lv = (ListView)convertView.findViewById(R.id.listView1);
holder.ed_Comment=(EditText) convertView.findViewById(R.id.edComment);
holder.btnSend=(Button) convertView.findViewById(R.id.btnSend);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
ct=new ArrayList<Comment>();
for(int j=0;j<listComment.size();j++){
Comment objComment=listComment.get(j);
ct.add(objComment);
}
myadapter = new CommentListAdapter(context,ct,a);
holder.lv.setAdapter(n);
holder.btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String text=edText.getText().toString();
Comment objComment=new Comment("1", "2", "1", "sadsa,"text",sadsa") ;
commentList.add(objComment);
myadapter.notifyDataSetChanged();
}
}
答案 0 :(得分:2)
您必须通知两个适配器,以便外部适配器知道它需要刷新其视图。您甚至可能需要通知外部适配器其数据集无效。