怎么给动态创建的ImageView添加个click listener?
我这是个rss读取的应用,这是我的代码:Iteratoritr=data.iterator();inti=0;while(itr.hasNext()){NewsPostD...
我这是个rss读取的应用,这是我的代码:Iterator itr = data.iterator(); int i =0; while (itr.hasNext()) { NewsPostDTO newspostdto = itr.next(); view = inflater.inflate(R.layout.rl_news_item, null); lnContentView.addView(view, LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); ivArrowfwd = (ImageView) view.findViewById(R.id.iv_arrowfwd); tvNewsHeading.setText(newspostdto.getFeaturedDesc()); tvNewsContent.setText(newspostdto.getDate() + " - " + newspostdto.getTitle()); ivArrowfwd.setId(id); ivArrowfwd.setTag(newspostdto); ivArrowfwd.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View arg0, MotionEvent arg1) { System.out.println("sdfsdf" +(ImageView) view.findViewById(id).getTag()); return false; } }); id++;}为什么不同的news没有产生不同的标签?谁能告诉我哪里做错了啊?
展开
1个回答
2013-09-22
展开全部
setOnTouchListener是不是你这个弄错了,用setOnClickListener ivArrowfwd.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View arg0, MotionEvent arg1) { System.out.println("sdfsdf" +(ImageView) view.findViewById(id).getTag()); return false; //执行完你的操作后,返回true } });
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询