它显示了未知的方法“ startsWith” 如果方法不正确,请告诉正确的方法
EditText editTxt = (EditText) findViewById(R.id.a);
WebView webv = (WebView) findViewById(R.id.b);
if (editTxt.startsWith("http://"){
webv.loadUrl(editTxt.getText().toString());
}else{
webv.loadUrl("http://" + editTxt.getText().toString());
}
答案 0 :(得分:2)
startsWith是String
的方法,您需要先转换为String:
String editTxtString = editTxt.getText().toString();
if (editTxtString .startsWith("http://")) {
webv.loadUrl(editTxtString);
} else {
webv.loadUrl("http://" + editTxtString);
}
或一支班轮:
webv.loadUrl(editTxtString .startsWith("http://")? editTxtString: "http://" + editTxtString);
答案 1 :(得分:1)
editText是字符串类吗?您可以发布一些代码,但是如果editText不是String类,可以尝试以下方法:
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:motion="http://schemas.android.com/apk/res-auto">
<ConstraintSet android:id="@+id/start">
<Constraint android:id="@id/menu">
<Layout
android:layout_width="0dp"
android:layout_height="wrap_content"
motion:layout_constraintBottom_toTopOf="parent"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</Constraint>
<Constraint android:id="@id/menuIndicator">
<Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toBottomOf="@id/menu" />
</Constraint>
</ConstraintSet>
<ConstraintSet
android:id="@+id/end"
motion:deriveConstraintsFrom="@id/start">
<Constraint android:id="@id/menu">
<Layout
android:layout_width="0dp"
android:layout_height="wrap_content"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent"
motion:layout_constraintTop_toTopOf="parent" />
</Constraint>
<Constraint android:id="@id/menuIndicator">
<Layout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
motion:layout_constraintBottom_toBottomOf="@id/menu"
motion:layout_constraintEnd_toEndOf="parent"
motion:layout_constraintStart_toStartOf="parent" />
</Constraint>
</ConstraintSet>
<!-- All the animations values are hardcoded for now. -->
<Transition
motion:constraintSetEnd="@+id/end"
motion:constraintSetStart="@+id/start"
motion:duration="400">
<OnSwipe
motion:dragDirection="dragDown"
motion:dragScale="0.5"
motion:maxAcceleration="10"
motion:maxVelocity="10.0" />
</Transition>
</MotionScene>