单击按钮时如何打开URL?

问题描述 投票:0回答:3

我有一个Button的问题。单击它时不会打开URL。不知道是什么问题。如果有人能提供帮助,我将不胜感激。谢谢。

public class Tours implements Serializable  {

 private String mId;
 private String mTitle;
 private String mYear;
 private String mCoord;

public Tours(){}

public Tours(String id, String title, String year, String coord) {
    this.mId = id;
    this.mTitle = title;
    this.mYear = year;
    this.mCoord = coord;
}

public String getId() {return mId;}

public void setId(String id) {this.mId = id;}

public String getTitle() {return mTitle;}

public void setTitle(String title) {this.mTitle = title;}

public String getYear() {return mYear;}

public void setYear(String year) {this.mYear = year;}

public String getCoord() {return mCoord;}

public void  setCoord(String coord) {this.mCoord = coord;}

}

android button android-intent
3个回答
0
投票

在你的oncreateVew()奶油刀里面初始化地方添加

 @Nullable
 @Override
 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
 container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.about_fragment, container, 
        false);
        ButterKnife.bind(getActivity(), view);
        return view;

}

@OnClick(R.id.bAbout)
public void someButtonOnClick(View view) {
 String url = "http://www.example.com";
 Intent i = new Intent(Intent.ACTION_VIEW);
 i.setData(Uri.parse(url));
 startActivity(i);
}

0
投票

添加Web视图

Webview webView=(WebView)findViewById(R.id.webView1);

并编写您想要执行任务的代码

String url="Your Url";
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(browserIntent);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);

0
投票

您在代码的某个点获得NullPointerException。可能在这一行:Tours.java:84但该代码不在你的帖子..

阅读:What is a NullPointerException, and how do I fix it?

© www.soinside.com 2019 - 2024. All rights reserved.