Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap Android Plugin issue trying to setContentView

I'm trying to get my first Android plugin to work. I've successfully registered it and able to execute it. Inside of my plugin execute action, I am trying to do the following:

ctx.setContentView(R.layout.map);

Which contains a new layout to load google maps; however, when I run this I receive the following error:

Only the original thread that created a view hierarchy can touch its views.

Any idea how I should go about doing this?

like image 234
endyourif Avatar asked Sep 02 '26 10:09

endyourif


1 Answers

You have to run it on UI thread. You can touch UI elements only on UI thread.

runOnUiThread(runb);

private Runnable runb = new Runnable() {

     public void run(){
           //call setContentView code here. 
     }
}
like image 99
Yashwanth Kumar Avatar answered Sep 05 '26 01:09

Yashwanth Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!