android中的动态列表视图按钮问题意图
我在动态列表视图按钮中有查询。我的动态列表视图中有 2 个按钮。我可以看到 onclick 事件并出现 toast。但是,当我尝试将意图传递给下一个活动时,它不起作用。请告诉我我哪里做错了。
我的代码:
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();
}
I have query in dynamic listview buttons. I have 2 buttons in my dynamic listview. I can see the onclick event and toast appears. But when I try to pass a intent to next activity it is not working. Kindly tell me where I am doing wrong.
My code:
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试更改您的
getContext()
代码以使用您的活动上下文。替换:
为:
编辑:修复了代码中的拼写错误。
Try changing your
getContext()
code to use your activity context.Replace:
With:
Edit: Fixed typo in code.