开发者

dynamic listview buttons problem intent in android

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;
     开发者_JS百科     @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();
 }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜