0
這裏是我的代碼:爲什麼吐司總是顯示10?
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.container);
for (i=0;i<10;i++) {
webView = new WebView(this);
webView.setId(i);
webView.getSettings().setJavaScriptEnabled(true);
String customHtml = "<p>WebView ID: <b>"+i+"</b></p>";
webView.loadData(customHtml, "text/html", "UTF-8");
webView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View view, MotionEvent motionEvent) {
Toast.makeText(getApplicationContext(),"i: "+i,Toast.LENGTH_SHORT).show();
return false;
}
});
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
lp.bottomMargin += 5;
linearLayout.addView(webView, lp);
}
我想顯示吐司的WebView ID,但它顯示10始終。
請幫助解決這個問題。
我想你有'我我;'作爲你的類實例變量? – marcinj
@marcin_j是的,我在課堂上宣佈它 – Metalik