编辑:现在完整的代码
package com.example.shopkart;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TextView;
public class netbanking extends Activity {
datamanager dm;
String name,mailid;
String[] productnamearray;
int[] amount_product,id_array;
boolean[] checkarray;
int tablesize,finalbill;
Spinner spinner_banks;
WebView wv1;
Button btnbankselect;
// @Override
// public void onBackPressed() {
//
// }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.netbanking);
dm=new datamanager(this);
wv1=(WebView) findViewById(R.id.wv1);
btnbankselect=(Button) findViewById(R.id.btnbankselect);
spinner_banks=(Spinner) findViewById(R.id.spinner_banks);
productnamearray=getIntent().getExtras().getStringArray("productnamearray");
checkarray=getIntent().getExtras().getBooleanArray("checkarray");
id_array=getIntent().getExtras().getIntArray("id_array");
name=getIntent().getExtras().getString("name");
mailid=getIntent().getExtras().getString("mailid");
finalbill=getIntent().getExtras().getInt("finalbill");
setspinnervalues();
btnbankselect.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
int pos=spinner_banks.getSelectedItemPosition();
switch (pos) {
case 0:
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("http://www.canarabank.in");
// Intent i1=new Intent(Intent.ACTION_VIEW);
// i1.setData(Uri.parse("http://www.google.com"));
// startActivity(i1);
break;
case 1:
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("http://www.federalbank.co.in");
// Intent i2=new Intent(Intent.ACTION_VIEW);
// i2.setData(Uri.parse("http://www.facebook.com"));
// startActivity(i2);
break;
case 2:
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("http://www.icicibank.com");
// Intent i3=new Intent(Intent.ACTION_VIEW);
// i3.setData(Uri.parse("http://www.icicibank.com"));
// startActivity(i3);
break;
case 3:
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("http://www.hdfcbank.com");
// Intent i4=new Intent(Intent.ACTION_VIEW);
// i4.setData(Uri.parse("http://www.hdfcbank.com"));
// startActivity(i4);
break;
case 4:
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("http://www.onlinesbi.com");
// Intent i5=new Intent(Intent.ACTION_VIEW);
// i5.setData(Uri.parse("http://www.onlinesbi.com"));
// startActivity(i5);
break;
}
}
});
}
public void setspinnervalues()
{
String[] arrvalues={"Canara Bank","Federal Bank","HDFC bank","ICICI bank","State bank of India"};
ArrayAdapter<String> arrap=new ArrayAdapter<String>(getApplicationContext(),R.layout.custom_spinner_item,arrvalues);
spinner_banks.setAdapter(arrap);
}
}
xml页面:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#F7F7F7"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Net banking Page"
android:textColor="#4B0082"
android:textSize="65px"
android:textStyle="bold"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose your bank from the below list"
android:textColor="#4B0082"
android:textSize="40px"
android:textStyle="bold"
android:layout_gravity="center"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner_banks"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="20px"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="25px"
android:text="Go to bank"
android:id="@+id/btnbankselect"
android:background="#4B0082"
android:textColor="#FFFFFF"
android:textSize="40px"
/>
<WebView
android:layout_width="wrap_content"
android:layout_height="110px"
android:id="@+id/wv1"
/>
</LinearLayout
浏览器强制关闭,webview没有打开。帮助!! 我已经删除了微调器事件,并且在按钮单击时加载了webview,而不是微调器项目选择的事件。
答案 0 :(得分:1)
请尝试以下代码了解浏览器意图:
//replace your bank link here
String link="http://www.bank.com";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(link));
startActivity(intent);