Wednesday, April 17, 2013

[android help] android web view not getting displayed as part of screen


my activity code



public class MainActivity extends Activity {
Spinner spinnerProduct;
WebView webView1, webView2, webView3;
private Handler mHandler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

spinnerProduct = (Spinner) findViewById(R.id.spinner_select_product);

List list = new ArrayList();
list.add("Product 1");
list.add("Product 2");
list.add("Product 3");

ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, list);
spinnerProduct.setAdapter(dataAdapter);

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinnerProduct.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getApplicationContext(), "Product " + ++arg2 + " selected", Toast.LENGTH_LONG).show();
showHtml();
}

@Override
public void onNothingSelected(AdapterView arg0) {
}
});
}

public void showHtml() {
Log.v("in showHtml", "in showHtml");
webView1 = (WebView) findViewById(R.id.web_view1);
WebSettings webSettings = webView1.getSettings();
webSettings.setJavaScriptEnabled(true);

webSettings.setSavePassword(true);
webSettings.setSaveFormData(true);
webSettings.setSupportZoom(true);

// webView1.addJavascriptInterface(new DemoJavaScriptInterface(),
// "demo");

webView1.loadUrl("file:///android_asset/product.html");

webView1.setWebChromeClient(new MyJavaScriptChromeClient(getApplicationContext()));
}}


My xml code



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:weightSum="10"
tools:context=".MainActivity" >

android:id="@+id/ll_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >

android:id="@+id/tv_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/app_name" />


android:id="@+id/ll_select_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:orientation="vertical" >

android:id="@+id/spinner_select_product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />


android:id="@+id/ll_web_views"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7"
android:orientation="horizontal"
android:weightSum="3" >

android:id="@+id/web_view1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />

android:id="@+id/web_view2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />

android:id="@+id/web_view3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />



I checked logcat, showHtml() method gets called(it prints "in html").


But web view doesn't get displayed.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...