开发者

R.id. values get overwritten

开发者 https://www.devze.com 2023-03-16 18:19 出处:网络
In my Android app I\'m creating new WebViews from Java code; however after I create these WebViews my previously working id\'s get overwritten.

In my Android app I'm creating new WebViews from Java code; however after I create these WebViews my previously working id's get overwritten.

Example snippet:

for (int i=0;i<mywebviewarray.length;i++){
    mywebviewarray开发者_开发知识库[i]=new WebView();
}
((Button)findViewById(R.id.mybutton).settext("ok");

If I run this code, I get an exception on the last line:

java.lang.ClassCastException: android.webkit.WebView

It seems to me as if the tables backing the findViewById get overwritten. I tried calling setId in the loop. but it does not help.

How can I resolve this problem?


What is in mywebviewarray. It seems to me like you have something in there that isnt a WebView and you are trying to instantiate it as a WebView.


I ended up not solving this problem, and instead of using a dynamic array of WebViews, I ended up using fixed 3 WebViews. I'm changing their content like a 3-length window over an array of URLs, thus simulating the original concept. (Albeit in a slower way)

0

精彩评论

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