Android 添加链接到按钮

发布于 2024-12-03 04:07:47 字数 1847 浏览 1 评论 0原文

我正在开发一个在同一视图中链接到视频和网站的应用程序。我遇到的问题是如何同时链接视频和链接以分离视图。这就是我到目前为止所拥有的:

private String videoUrl;
private String fullUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 setContentView(R.layout.details);
 TextView detailsTitle = (TextView)findViewById(R.id.detailstitle);
 TextView detailsDescription = (TextView)findViewById(R.id.detailsdescription);
 TextView detailsPubdate = (TextView)findViewById(R.id.detailspubdate);
 TextView detailsLink = (TextView)findViewById(R.id.detailslink);
 TextView detailsEnclosure = (TextView)findViewById(R.id.detailsenclosure);
 Button linkButton = (Button)findViewById(R.id.linkButton);

 View VideoPlay = findViewById(R.id.videoButton);
 VideoPlay.setOnClickListener(this);

  Bundle bundle = this.getIntent().getExtras(); 

  detailsTitle.setText(bundle.getString("keyTitle"));
  detailsDescription.setText(bundle.getString("keyDescription"));
  detailsPubdate.setText(bundle.getString("keyPubdate"));
  detailsLink.setText(bundle.getString("keyLink"));
  linkButton.setText("View this in full website");


  videoUrl = bundle.getString("keyEnclosure");
  fullUrl = bundle.getString("keyLink");
}

//Process the button click events
    public void onClick(View videoplayer) {
        Intent VideoPlay = new Intent(this, VideoPlayer.class);
        VideoPlay.putExtra("url",videoUrl);
        startActivity(VideoPlay);
    }
    public void openWebURL(String fullUrl){
        Intent Browse = new Intent(Intent.ACTION_VIEW, Uri.parse (fullUrl));
        Browse.putExtra(com.CalvaryChapelMelbourne.CCM.Webscreen.URL, 
                "fullUrl");
        startActivity(Browse);
    }
}

视频按钮工作正常,但链接按钮根本不起作用。这就是我运行它时的样子。

请链接帮助!

I am working on an app that links to a video and a website in the same view. The problem I am having is how to link the video and the link at the same time to separate views. This is what I have so far:

private String videoUrl;
private String fullUrl;

@Override
protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 setContentView(R.layout.details);
 TextView detailsTitle = (TextView)findViewById(R.id.detailstitle);
 TextView detailsDescription = (TextView)findViewById(R.id.detailsdescription);
 TextView detailsPubdate = (TextView)findViewById(R.id.detailspubdate);
 TextView detailsLink = (TextView)findViewById(R.id.detailslink);
 TextView detailsEnclosure = (TextView)findViewById(R.id.detailsenclosure);
 Button linkButton = (Button)findViewById(R.id.linkButton);

 View VideoPlay = findViewById(R.id.videoButton);
 VideoPlay.setOnClickListener(this);

  Bundle bundle = this.getIntent().getExtras(); 

  detailsTitle.setText(bundle.getString("keyTitle"));
  detailsDescription.setText(bundle.getString("keyDescription"));
  detailsPubdate.setText(bundle.getString("keyPubdate"));
  detailsLink.setText(bundle.getString("keyLink"));
  linkButton.setText("View this in full website");


  videoUrl = bundle.getString("keyEnclosure");
  fullUrl = bundle.getString("keyLink");
}

//Process the button click events
    public void onClick(View videoplayer) {
        Intent VideoPlay = new Intent(this, VideoPlayer.class);
        VideoPlay.putExtra("url",videoUrl);
        startActivity(VideoPlay);
    }
    public void openWebURL(String fullUrl){
        Intent Browse = new Intent(Intent.ACTION_VIEW, Uri.parse (fullUrl));
        Browse.putExtra(com.CalvaryChapelMelbourne.CCM.Webscreen.URL, 
                "fullUrl");
        startActivity(Browse);
    }
}

The video button works fine, but the link button doesn't work at all. This is what it looks like when I run it.

Link Help Please!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城花音 2024-12-10 04:07:47

更改您的 openWebUrl() 方法以匹配此方法,它将解决您的问题。

public void openWebURL(String fullUrl){
    Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(fullUrl));
    startActivity(intent);
}

Change your openWebUrl() method to match this, it will fix your problem.

public void openWebURL(String fullUrl){
    Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(fullUrl));
    startActivity(intent);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文