Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8773731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:22:39+00:00 2026-06-13T18:22:39+00:00

i’m not copying all the code cause it’s too long, but to be concise

  • 0

i’m not copying all the code cause it’s too long, but to be concise :

i have a fonction (recup_list_internet) which has a thread in it, which retrieve data from internet (an XML), decoding it, and assign each “node” to an element in my adapter.

When doing the decoding outside the Thread, everything works fine.
So i modify this to be used inside the thread, create a void run() function in it, displaying my progressDialog, decoding, data is well retrieved, well assigned to my map (=new HashMap();)
and here is where the problem appears

private void recup_list_internet()
{
final ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
final Context mContext=this.getBaseContext();


Thread t = new Thread()
{
    public void run()
    {/* the code here works fine, not displaying it to be more concise*/

    progressDialog.dismiss(); //works fine
    SimpleAdapter mSchedule = new SimpleAdapter (mContext, listItem, R.layout.affiche_boutique,new String[] {"img", "titre", "description","Prix","uniqueID"}, new int[] {R.id.img,R.id.titre, R.id.description,R.id.prix,R.id.uniqueID}); //works fine
    maListViewPerso.setAdapter(mSchedule); //doesn't work
    }
};
t.start();
}

here is my log cat :

11-04 19:20:33.070: E/recuperation phonster(546): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

It seems that i’m unable to “access” to maListViewPero while in my thread…
(maListViewPerso is defined previously in my onCreate code :

public class DisplayInternet  extends Activity{
private ListView maListViewPerso;
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ceinture_lv);
    maListViewPerso = (ListView) findViewById(R.id.listviewperso);
    recup_list_internet();
}   

so where can i put this line for its to works ?
“maListViewPerso.setAdapter(mSchedule);”

because i already try to declare mSchedule outside my thread (in final) but inside my Thread, i’m unable to access it (and so, i’m unable to use it after the “t.start()” line

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T18:22:41+00:00Added an answer on June 13, 2026 at 6:22 pm

    Inside your thread, use:

    View.post(Runnable r)

    which basically says “hey, UI thread, execute this thing for me” – and put in the runnable all the code which must be executed in the UI thread – this is particularly useful when you have a thread retrieving data from the network (which must not run on the UI thread) but then must post the results on the UI (which must be done from the UI thread)

    example:

    view.post(new Runnable(){ 
        public void run(){
            //put all the code you want to be execute on the UI thread here
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I want to count how many characters a certain string has in PHP, but
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.