开发者

how to load parsed data into an existing textview(existing layout) in android

hii every buddy , am not getting how to load parsed dat开发者_Python百科a into an existing textview(existing layout) in android, insted of loading data to the new textview like how they r doing in the following tutorial(check the following link)

check this link for tutorial


In the tutorial they do:

TextView something = new TextView(context);

As you don't want to do so (good decision), you get the reference to the existent TextView:

TextView something = (TextView)findViewById(R.id.the_id_you_gave_it_in_the_xml);
// then:
something.setText(theParsedString);


Try this code using existing Layout

Textview name=(TextView)findViewById(R.id.textView1);
        String txt="";
        for(int i=0;i<sitesList.getName().size();i++)
        {
             txt=txt+sitesList.getName().get(i).toString();


        }
name.setText(txt);


Sowmya It seems that you are creating multiple textviews & trying to update those textviews .In that case you need to use setTag() and getTag() .

There is an example you can find here

Regarding your answer:

we r declaring textview array so am unable to load to existing textview

I have never implemented such a textview array instead the best practice would be to

    for (String s : stringarray) {
          TextView tv = new TextView (this);
          tv.setText(s);
          tv.setTag("1");
         linearlayout.addView(tv);
        }

*EDIT:*For those enthusiast out there I found 2 more methods:

One is using setId() to manually set ID of that textview & then find it by findViewById()

Another method(is though not implemented by me , but is a suggestion by my colleague so dont kill me if it doesn't works) is to store textview objects in an arraylist & then access them & do whatever you want whoa!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜