1

I have an activity in my app which displays rss feeds and next to each rss feed arrow image is attached.. i want to attach the news object to the arrow so that when it is clicked i can pass that object to the next activity an dislay the details ??

I am new to android any help will be appreciated.

Update : I have updated my code and now i am using setTag with my image view to attach an object with it ... but actually first i shall explain what i am doing to display rss news ...

i have a seperate dummy xml layout for a single rss.. i have set id for arrow image (which will navigate o the next activity) in it as iv_arrow_img
i am itterating over the news feeds i get and for each news feed i am adding the dummy view again and again...my question is how will i distinguish between different image arrow's ids .. because for now all are having the same id... how will i set onclick listeners to them ???

updated :sample code

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.setTag(newspostdto.getId());
    ivArrowfwd.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {

            System.out.println("sdfsdf" +ivArrowfwd.getTag());

            return false;

    });
}

getTag() is not returnig unique values .. i am geting same value on each news arrow when i click it ...

madiha.athar
  • 1,103
  • 3
  • 12
  • 25

2 Answers2

4

To assign object to any image view you can use setTag() method and to retirieve the information on you can use getTag() method

Example

ImageView iv = (ImageView)findViewById(R.id.imageview001);
        iv.setTag(objectassignedToTheImage);
        iv.setOnClickListener(new OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Object passToIntent =iv.getTag()
            }
        });

Thanks Deepak

Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
  • I have updated my code and now i am using setTag with my image view to attach an object with it ... but actually first i shall explain what i am doing to display rss news ... i have a seperate dummy xml layout for a single rss.. i have set id for arrow image (which will navigate o the next activity) in it as iv_arrow_img i am itterating over the news feeds i get and for each news feed i am adding the dummy view again and again...my question is how will i distinguish between different image arrow's ids .. because for now all are having the same id... how will i set onclick listeners to them – madiha.athar Jun 16 '11 at 05:33
2

Data can be passed between activities by adding it to the Intent object. Please check this question for how to do this: How to send an object from one Android Activity to another using Intents?

That said, I'd highly recommend using an MVC pattern.

Community
  • 1
  • 1
sparkymat
  • 9,938
  • 3
  • 30
  • 48
  • I think u idnot understand my question .. i have multiple arrow images on my activity i want to attach each arrow its newsto atow h object attach so that when it is clicked ican get it back that object .. iknow how to pass it to activity... but first i want to get the associated object... – madiha.athar Jun 16 '11 at 05:14
  • Yes. I had misunderstood your question. I think Deepak has answered it correctly. – sparkymat Jun 16 '11 at 05:47