Web View活动是:
public class show extends AppCompatActivity {
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show);
myWebView = (WebView)findViewById(R.id.orderlink);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
Intent intent = getIntent();
int restu = intent.getIntExtra("restu", 0);
// myWebView.loadUrl("https://www.foodmart.com.bd/index.php?Theme=default&Base=Page&Script=MenuPage&id=556");
switch(restu){
case 1:
myWebView.loadUrl("https://www.foodmart.com.bd/index.php?Theme=default&Base=Page&Script=MenuPage&id=556");
case 2:
myWebView.loadUrl("https://www.foodpanda.com/");
}
}
}
我的主要活动:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
void Click(View v){
switch(v.getId()){
case R.id.order1 :
Intent p = new Intent(MainActivity.this, show.class);
p.putExtra("restu",1);
startActivity(p);
break;
case R.id.order2 :
Intent q = new Intent(MainActivity.this, show.class);
q.putExtra("restu",2);
startActivity(q);
}
}
}
我想从按钮点击打开不同的网页。问题在哪里请帮助我........................................... .................................................. .................................................. ...............
答案 0 :(得分:0)
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button b,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button)findViewById(R.id.order1); //add with button id
b2=(Button)findViewById(R.id.order2);
b.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.order1 :
Intent p = new Intent(getBaseContext(), show.class);
p.putExtra("restu",1);
startActivity(p);
break;
case R.id.order2 :
Intent q = new Intent(getBaseContext(), show.class);
q.putExtra("restu",2);
startActivity(q);
break;
}
}
}
将您的主要活动更改为此。并使用getBaseContext()
答案 1 :(得分:0)
在每种情况下使用break。按钮点击监听器实现.Rest似乎很好。
答案 2 :(得分:0)
试试这个,在每种情况下添加休息。
switch(restu){
case 1:
myWebView.loadUrl("https://www.foodmart.com.bd/index.php?Theme=default&Base=Page&Script=MenuPage&id=556");
break;
case 2:
myWebView.loadUrl("https://www.foodpanda.com/");
break;
default:
Log.d("what??", "something must be wrong")
break;
}