我如何通过从一个活动的信息的EditText到另一个网址在新的活动的的WebView加载? [英] How do I pass info from one activity's EditText to another for the url to be loaded in that new activity's WebView?

查看:134
本文介绍了我如何通过从一个活动的信息的EditText到另一个网址在新的活动的的WebView加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切!我已经通过计算器了几个小时,现在搜索和无法找到解决我的问题。

all! I have been searching through StackOverflow for a few hours now and cannot find a solution to my problem.

我正在开发一款Android应用,需要采取通过从一个EditText在一个活动的用户输入(这恰好是一个int值)。然后我需要的EditText的int值要传递给第二个活动,并解析成一个URL装载到该次活动网页视图。但是,我不能得到这个工作。事实上,我不能让我的WebView在所有的工作,甚至试图加载像谷歌的网站。下面是我的code。

I am developing an android app that needs to take input from the user in one activity through an EditText (this happens to be an int value). I then need that EditText's int value to be passed to a second activity, and parsed into a url to be loaded into a webview in that second activity. However, I cannot get this to work. In fact, I cannot get my WebView to work at all, even trying to load websites like Google. Below is my code.

public void takeInput(View view) {
        Intent intent = new Intent(this, WebViewActivity.class);
        EditText editText = (EditText) findViewById(R.id.editText);
        Integer vendorID = Integer.parseInt(editText.getText().toString());
        intent.putExtra(EXTRA_VENDORID, vendorID);
        startActivity(intent);

以上是被称为当屏幕上的按钮是pressed的OnClick方法。

Above is the method that is called when an onscreen button is pressed OnClick.

这是下一个活动的code如下。

The code from the next activity is below.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    String testURL2 = "www.google.com";
    WebView streetwiseSite = (WebView) this.findViewById(R.id.webView);
    streetwiseSite.getSettings().setJavaScriptEnabled(true);
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    String vendorID = extras.getString(MainActivity.EXTRA_VENDORID);
    Integer vendorID = Integer.parseInt(extras.getString(MainActivity.EXTRA_VENDORID));
    String targetURL = "www.something.org/purchase/";

下面是XML code为我的第一个活动。

Here is the XML code for my first activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="@drawable/logo" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:text="MobilePay"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:hint="Vendor ID #"
        android:inputType="number" />


    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="72dp"
        android:onClick="takeInput"
        android:text="Pay" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="34dp"
        android:text="Enter Vendor ID and"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:text="Payment Amount to Pay"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

下面是我的XML code代表的WebView活动,第二个活动。

Here is my XML code for the WebView activity, the second activity.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.august.streetwise.WebViewActivity">


    <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />
</RelativeLayout>

在理想情况下应该采取用户的输入,其解析到URL,并加载该网站。然而,这里是我从logcat中得到错误。

Ideally this should take the user's input, parse it into the URL, and load that website. However, here are the errors I get from logcat.

23 04-21:36:14.837 17904-17904 / com.myname.app W / BindingManager的:不能调用determinedVisibility() - 从未见过的PID的连接:17904

04-21 23:36:14.837 17904-17904/com.myname.app W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid: 17904

任何想法?我已经出来拉我的头发了这一点。

Any ideas? I've been pulling my hair out over this.

推荐答案

WebView.loadUrl()中不添加任何协议格式化字符串的开头。因此, www.something.org 不会自动成为 http://www.something.org

WebView.loadUrl() does not add any protocol formatting to the beginning of the string. Therefore, www.something.org does not automatically become http://www.something.org.

如果没有在字符串开头的协议信息, WebView.loadUrl()抛出断然无益的误差 W / BindingManager的:不能叫determinedVisibility () - 从未见过的PID的连接,因为 www.something.org 不是一个完整的网址

Without the protocol information at the beginning of the string, WebView.loadUrl() throws the decidedly unhelpful error W/BindingManager﹕ Cannot call determinedVisibility() - never saw a connection for the pid because www.something.org isn't a complete URL.

您可能会认为这种行为会被记录在案的地方。 ;)

You would think this behavior would be documented somewhere. ;)

这篇关于我如何通过从一个活动的信息的EditText到另一个网址在新的活动的的WebView加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆