android中的动态列表视图按钮问题意图

发布于 2024-12-02 02:19:49 字数 2244 浏览 0 评论 0原文

我在动态列表视图按钮中有查询。我的动态列表视图中有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-12-09 02:19:49

尝试更改您的 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);

编辑:修复了代码中的拼写错误。

Try changing your getContext() code to use your activity context.

Replace:

        Intent myIntent = new Intent(v.getContext(), messsagelist.class);
        //startActivity(myIntent);

        this.startActivityForResult(myIntent, 0);

With:

        Intent myIntent = new Intent(yourActivityName.this, messsagelist.class);
        //startActivity(myIntent);

        this.startActivityForResult(myIntent, 0);

Edit: Fixed typo in code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文