Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建具有多个weblink按钮的应用程序_Android_Button - Fatal编程技术网

Android 创建具有多个weblink按钮的应用程序

Android 创建具有多个weblink按钮的应用程序,android,button,Android,Button,我是一个新的程序员,试图找出哪里出了问题。我的目的是制作一个带有多个按钮的应用程序,每个按钮链接到不同的网站。我一直在使用来自web的代码,但当我尝试添加uri.parse并绞尽脑汁寻找解决方案时,仍然不确定为什么它无法编译。 所以现在我从一个基线示例开始,尝试对其进行反向工程以理解。我想要的按钮,以导致一个网站,而不是设置文本。我尝试过多种解决方案,但都不管用,我猜你们可以在睡梦中回答这个问题。谢谢 伙计们,我知道了,谢谢! 下面是工作java 公共类MainActivity扩展活动实现OnC

我是一个新的程序员,试图找出哪里出了问题。我的目的是制作一个带有多个按钮的应用程序,每个按钮链接到不同的网站。我一直在使用来自web的代码,但当我尝试添加uri.parse并绞尽脑汁寻找解决方案时,仍然不确定为什么它无法编译。 所以现在我从一个基线示例开始,尝试对其进行反向工程以理解。我想要的按钮,以导致一个网站,而不是设置文本。我尝试过多种解决方案,但都不管用,我猜你们可以在睡梦中回答这个问题。谢谢

伙计们,我知道了,谢谢! 下面是工作java

公共类MainActivity扩展活动实现OnClickListener{

TextView tvOut;
Button btnOk;
Button btnCancel;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // find View-elements
    tvOut = (TextView) findViewById(R.id.tvOut);
    btnOk = (Button) findViewById(R.id.btnOk);
    btnCancel = (Button) findViewById(R.id.btnCancel);

    // assign listeners to buttons
    btnOk.setOnClickListener(this);
    btnCancel.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // define the button that invoked the listener by id
    switch (v.getId()) {
        case R.id.btnOk:
        // ОК button// Open Website
        Intent intent;

        try {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/yourPage"));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            } catch (Exception e) {
            Log.e("Exception Caught", e.toString());
        }

        break;
        case R.id.btnCancel:
        // Cancel button
        Intent intent2;

        try {
            intent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/yourPage"));
            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent2);
            } catch (Exception e) {
            Log.e("Exception Caught", e.toString());
        }
        break;
    }
}

}

如果要在应用程序中保留网页的上下文,则需要在活动布局中添加网络视图:

    <RelativeLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity">
       <WebView
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:id="@+id/webView"
               android:layout_centerVertical="true"
               android:layout_centerHorizontal="true"/>
     </RelativeLayout>
您需要将以下内容添加到清单中:

<uses-permission android:name="android.permission.INTERNET" />

这样你就可以控制局面。。否则,你需要有目的地去做。简单的示例和文档如下:


您是否面临任何错误?我在发布后才发现。我将把这个例子留给其他提出同样问题的人。你可以将你的工作解决方案作为你自己问题的答案发布,并接受它。不要把工作代码放入你的问题中;相反,将不起作用的代码留在那里,这样其他人就可以看到哪里出了问题,解决方案是什么。明白了,请先发帖抱歉
<uses-permission android:name="android.permission.INTERNET" />