我只想问你如何将Webview与edittext中输入的字符串一起使用? 例如,我创建了2个片段,其中一个片段显示webview,另一个片段从用户那里获取2个edittext。我只想获取从2.片段到1.片段输入的edittext值。因为我要创建这样的URL:webView.loadUrl(“ http://www.truebilisim.com/myiphone/index.php?id=” + ID +“&sifre =” +密码);
这是我的第一个片段。
<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>
答案 0 :(得分:0)
您的问题太大,无法在此处回答。其不具体。我只想提一下步骤。如果搜索正确,您将找到特定零件的代码。
初始化您的EditText
。您将在用户单击登录按钮时从EditText
发送值。
在登录按钮上设置onClickListener
。在侦听器内部,检查您的EditTexts
是否有价值。如果它们有价值,请转到另一个片段。
将EditText
的值发送到另一个片段,您可以通过多种方式进行操作。一种是,只需将实例获取到目标片段对象,然后发送值。
答案 1 :(得分:0)
我像这样得到这些字符串,但找不到第一个片段的使用方法。你可以告诉我吗?
public class Tab2 extends Fragment {
public Tab2() {
// Required empty public constructor
}
EditText ed1,ed2;
private Button b1;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab2, container, false);
b1 = view.findViewById(R.id.btn_login);
ed1 = view.findViewById(R.id.idx);
ed2 = view.findViewById(R.id.password);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String n = ed1.getText().toString();
String p = ed2.getText().toString();
}
});
return view;
}
}