我在动态列表视图按钮中查询。我的动态列表视图中有2个按钮。我可以看到onclick事件和吐司出现。但是,当我尝试将意图传递给下一个活动时,它无法正常工作。请告诉我我做错了什么。
我的代码:
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.adaptor_content, null);
// Creates a ViewHolder and store references to the two children
// views
// we want to bind data to.
holder = new ViewHolder();
holder.textLine = (TextView) convertView.findViewById(R.id.textLine);
// holder.iconLine = (ImageView) convertView.findViewById(R.id.iconLine);
holder.buttonLine = (Button) convertView.findViewById(R.id.buttonLine);
holder.DbuttonLine = (Button) convertView.findViewById(R.id.DbuttonLine);
holder.textLine2 =(TextView) convertView.findViewById(R.id.textLine2);
holder.mobile =(TextView) convertView.findViewById(R.id.mobile);
holder.newmes =(TextView) convertView.findViewById(R.id.newmessage);
convertView.setOnClickListener(new OnClickListener() {
private int pos = position;
@Override
public void onClick(View v) {
Toast.makeText(context, "Click-" + String.valueOf(pos), Toast.LENGTH_SHORT).show();
}
});
holder.buttonLine.setOnClickListener(new OnClickListener(){
private int pos = position;
@Override
public void onClick(View v) {
//Toast.makeText(context, "Delete-" + String.valueOf(pos), Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(v.getContext(), messsagelist.class);
//startActivity(myIntent);
this.startActivityForResult(myIntent, 0);
}
private void startActivityForResult(Intent myIntent, int i) {
// TODO Auto-generated method stub
}
});
holder.DbuttonLine.setOnClickListener(new OnClickListener() {
private int pos = position;
@Override
public void onClick(View v) {
Toast.makeText(context, "Details-" + String.valueOf(pos), Toast.LENGTH_SHORT).show();
}
});
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
答案 0 :(得分:0)
尝试更改getContext()
代码以使用您的活动背景。
替换:
Intent myIntent = new Intent(v.getContext(), messsagelist.class);
//startActivity(myIntent);
this.startActivityForResult(myIntent, 0);
使用:
Intent myIntent = new Intent(yourActivityName.this, messsagelist.class);
//startActivity(myIntent);
this.startActivityForResult(myIntent, 0);
编辑:修正了代码中的拼写错误。