android - 将 webview 与输入的字符串值一起使用

标签 android android-webview

我只想问你如何使用 webview 和来自 edittext 的输入字符串? 例如,我创建了 2 个 fragment ,其中一个显示 webview,另一个从用户那里获取 2 个编辑文本。我只想输入从 2.fragment 到 1.fragment 的 edittext 值。因为我想创建一个这样的 URL:webView.loadUrl("http://www.truebilisim.com/myiphone/index.php?id= "+ ID + "&sifre="+ Password);

这是我的第一个 fragment 。

<FrameLayout 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"
tools:context=".Tab1">

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

这是第二个。

<FrameLayout 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"
tools:context=".Tab2">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:paddingTop="80dp"
    android:paddingRight="30dp"
    android:paddingLeft="30dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Tab2">

    <ImageView
        android:src="@drawable/logo_small"
        android:id="@+id/logo"
        android:layout_marginBottom="30dp"
        android:layout_width="match_parent"
        android:layout_height="100dp" />
    <android.support.design.widget.TextInputLayout
        android:id="@+id/layout_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/logo">

        <EditText

            android:hint="ID"
            android:textColor="@color/colorPrimary"
            android:id="@+id/idx"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>
    <android.support.design.widget.TextInputLayout
        android:id="@+id/layout_pass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/layout_id"
        >

        <EditText
            android:inputType="textPassword"
            android:hint="Şifre"
            android:textColor="@color/colorPrimary"
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.TextInputLayout>

    <Button
        android:id="@+id/btn_login"
        android:layout_below="@id/layout_pass"
        android:backgroundTint="@color/colorPrimaryDark"
        android:text="KAYDET"
        android:layout_marginTop="30dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         />
</RelativeLayout>

最佳答案

您的问题太大,无法在这里回答。它不具体。我只是想提一下步骤。如果搜索得当,您会找到特定部分的代码。

  • 初始化您的 EditText。当用户点击登录按钮时,您将发送来自 EditText 的值。

  • 在登录按钮上设置onClickListener。在监听器内部,检查您的 EditTexts 是否有值(value)。如果它们有值(value),请转到另一个 fragment 。

  • EditText 的值发送到另一个 fragment ,您可以通过多种方式执行此操作。一种是,只获取目标 fragment 对象的实例,然后发送值。

关于android - 将 webview 与输入的字符串值一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54686274/

相关文章:

android - 如何在 android 中将 Intent 从 Activity 转换为 Fragment?

java - 返回对话框时 MapView 未加载(MapBox)

android - 动态android字符串资源

javascript - 从 Android 设置 JavaScript 变量值

android - phonegap 3.3.0 中的本地通知

android - 无法从 IP 摄像头接收 RTSP 实时流

android - WebView 无法加载 oAuth 网址

android - 使用 Amazon Device Farm 或类似工具检查浏览器

php - 在 webView 中 PHP 登录后发送 Firebase 注册 token

android - 浏览所有网站,所有链接都在同一个 webview 中打开