mohan
mohan

Reputation: 13165

How to pass array of value to another activity in android

I am getting the dynamic value from a web server like article desc, date,title etc. For one value article id, desc display in one webview. I am using array of webview. My requirement is that if the user clicks the first webview, I have to pass the first article id to another activity.

Can anybody tell me how to pass an array value to another activity?
Can anybody give an example?

This code explains I am getting the value from webservice and stored in arraylist and iterate the array list and display in webview and implement in touch event. My requirement is if user touch the first view. I have to pass first article id to another activity can anybody tell how to do this?

ArrayList articleParsedValue=new ArrayList();
articleParsedValue=articleParser.parseXmlArticle(webservicevalue);

for(int i=0;i<articleParsedValue.size();i++)
        {
                ArticleDataSet articleDataset=(ArticleDataSet)articleParsedValue.get(i);
                HashMap<String, String> mapValue=new HashMap<String, String>();  

            WebView webviewcontent=new WebView(this);
           String html ="<html><body><div><label style=\"font:bold 17.5px verdana; color:#C1002B\">"+articleDataset.getArticle_title()+"<label style=\"font:13px verdana; color:#000000\">"+"|"+"</label>"+"<label style=\"font:bold 13px verdana; color:#000000\">"+articleDataset.getArticle_type()+"</label><br><label style=\"font:13px verdana; color:#AAAAAA\">"+articleDataset.getArticle_date()+" </label> </div>";
           html=html+"<div><label style=\"font:13px verdana; color:#000000\">"+articleDataset.getArticle_summary()+"</label></div></body></html>" ;
           webviewcontent.getSettings().setJavaScriptEnabled(true);
           webviewcontent.clearCache(true);
           webviewcontent.loadData(html, "text/html", "utf-8");
          webviewcontent.setOnTouchListener(this);
             mainlinear2.addView(webviewcontent);


        }


@Override
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub

    {



            Intent newIntent=new Intent(this,MyCompaniesActivity.class);
            //newIntent.putExtra("articleid", ); 
            startActivity(newIntent);
            return false;
        }

Upvotes: 0

Views: 1353

Answers (2)

kgiannakakis
kgiannakakis

Reputation: 104178

You can use one of the Intent.putExtra methods. Then from the other activity use Intent.getExtra.

Upvotes: 3

ykatchou
ykatchou

Reputation: 3727

You should use intents : http://developer.android.com/guide/topics/intents/intents-filters.html

Upvotes: 0

Related Questions