开发者

R.id. values 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜