我是 kotlin 的初学者,我正在尝试过滤一个列表中存在的项目,但是我为此使用了循环和迭代器。我在in这里的 if 条件中被提及异常。有人可以指导我哪里出错了。我在这里粘贴我的功能。
fun getGateWays(
gateways: ArrayList<JsonObject>?,
callback: ResponseCallback<ArrayList<JsonObject>, String>
) {
getDistinctGateways(object : ResponseCallback<List<String>?, String>() {
override fun onFailure(failure: String) {
}
override fun onSuccess(response: List<String>?) {
for(e in gateways!!.iterator()){
if(e.get("value") in response){
gateways.remove(e)
}
}
callback.onSuccess(gateways!!)
}
})
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 android 中实现数据绑定示例并创建一个带有可绑定变量的 POJO,我收到此错误!请帮忙。我正在关注本教程 http://www.vogella.com/tutorials/AndroidDatabinding/article.html,这是我的代码
import android.databinding.BaseObservable;
import android.databinding.Bindable;
public class TemperatureData extends BaseObservable {
private String location;
private String celsius;
public TemperatureData(String location, String celsius) {
this.location = location;
this.celsius = celsius;
}
@Bindable
public String getCelsius() {
return celsius;
}
@Bindable
public String getLocation() {
return location;
}
public void setLocation(String location){
this.location = location;
notifyPropertyChanged(BR.location);
}
public void setCelsius(String celsius) {
this.celsius = celsius;
notifyPropertyChanged(BR.celsius);
}
}
Run Code Online (Sandbox Code Playgroud) startActivityForResult(intent,3021)
Run Code Online (Sandbox Code Playgroud)
我用了很长时间了,现在不推荐使用这种方法了吗?
我最近迁移到最新的回调机制来注册请求权限,但是用于注册请求回调的最新 api 从未被触发我正在附加代码片段,任何人都可以帮助我找到问题所在,
@AndroidEntryPoint
class ManageTeamFragment : Fragment(), View.OnClickListener {
@Inject
lateinit var manageTeamViewModel: ManageTeamViewModel
private var requestMultiplePermissions:ActivityResultLauncher<Array<out String>>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestMultiplePermissions =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
println("DEBUG $it")
if (allPermissionsGranted()) {
btnAddUser.showLoading(true)
btnAddUser.postDelayed({
(activity as? DashboardActivity)?.navToFragment(AddUserFragment(), true)
}, 10)
} else {
if (addOrEditUserBottomSheet == null) {
addOrEditUserBottomSheet =
AddOrEditUserBottomSheet(toolbar.context, addOrEditUserInteractionsListener)
}
addOrEditUserBottomSheet?.showBottomSheet()
}
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_manage_team, container, false)
}
override fun …Run Code Online (Sandbox Code Playgroud) 我正在使用房间数据库来创建本地存储,我正在尝试迁移数据库,并且在多次调用迁移函数时遇到问题。
我在这里附上我的一段代码。
class DbInstance {
companion object {
private var db: AppDatabase? = null
fun getDbInstance(context: Context): AppDatabase {
if (db == null)
db = Room.databaseBuilder(
context,
AppDatabase::class.java, "mydb"
)
.addMigrations(MIGRATION_1_2, MIGRATION_2_3)
.build()
return db!!
}
private val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
}
}
private val MIGRATION_2_3 = object : Migration(2, 3) {
override fun migrate(database: SupportSQLiteDatabase) {
println("------> called for MIGRATION_2_3")
database.execSQL(
"Alter table PaymentDB add column ui_name text"
)
} …Run Code Online (Sandbox Code Playgroud) 面对喷气背包组合中的一次崩溃,任何人都可以帮助我解决这个问题。
Fatal Exception: java.lang.IllegalArgumentException: offset(23) is out of bounds [0, 0]
at androidx.compose.ui.text.MultiParagraph.requireIndexInRangeInclusiveEnd(MultiParagraph.kt:593)
at androidx.compose.ui.text.MultiParagraph.getBidiRunDirection(MultiParagraph.kt:406)
at androidx.compose.ui.text.TextLayoutResult.getBidiRunDirection(TextLayoutResult.kt:353)
at androidx.compose.foundation.text.CoreTextFieldKt.SelectionToolbarAndHandles(CoreTextField.kt:816)
at androidx.compose.foundation.text.CoreTextFieldKt.access$SelectionToolbarAndHandles(CoreTextField.kt:1)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1$1.invoke(CoreTextField.kt:565)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1$1.invoke(CoreTextField.kt:527)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposablesKt.ReusableComposeNode(ComposablesKt.java:443)
at androidx.compose.foundation.text.selection.SimpleLayoutKt.SimpleLayout(SimpleLayout.kt:79)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1.invoke(CoreTextField.kt:527)
at androidx.compose.foundation.text.CoreTextFieldKt$CoreTextField$4$1.invoke(CoreTextField.kt:510)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.material.OutlinedTextFieldKt.IconsWithTextFieldLayout-T2E5_Oc(OutlinedTextField.kt:452)
at androidx.compose.material.OutlinedTextFieldKt.access$OutlinedTextField$lambda-3(OutlinedTextField.kt:1)
at androidx.compose.material.OutlinedTextFieldKt$OutlinedTextFieldLayout$1.invoke(OutlinedTextField.kt:350)
at androidx.compose.material.OutlinedTextFieldKt$OutlinedTextFieldLayout$1.invoke(OutlinedTextField.kt:348)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.foundation.text.CoreTextFieldKt.CoreTextField(CoreTextField.kt:510)
at androidx.compose.foundation.text.BasicTextFieldKt.BasicTextField(BasicTextField.kt:262)
at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextFieldLayout-uBqXD2s(OutlinedTextField.kt:322)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$3.invoke-h1eT-Ww(TextFieldImpl.kt:207)
at androidx.compose.material.TextFieldImplKt$TextFieldImpl$3.invoke(TextFieldImpl.kt:129)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:214)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.material.TextFieldTransitionScope.Transition-DTcfvLk(TextFieldImpl.kt:357)
at androidx.compose.material.TextFieldImplKt.TextFieldImpl(TextFieldImpl.kt:119)
at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:270)
at androidx.compose.material.OutlinedTextFieldKt.OutlinedTextField(OutlinedTextField.kt:157)
at com.zee5.presentation.search.searchrefinement.composable.SearchRefinementScreenKt.TopTextInputView(SearchRefinementScreen.kt:131)
at com.zee5.presentation.search.searchrefinement.composable.SearchRefinementScreenKt.SearchRefinementScreen(SearchRefinementScreen.kt:74)
at …Run Code Online (Sandbox Code Playgroud) 这是我的代码: -
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);`langData = "hi"`
setLocale(langData);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//setLocale(langData);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish();
}
}, 3000);
}
public void setLocale(String lang) {
Resources res = this.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
setSystemLocale(conf, new Locale(lang.toLowerCase()));
} else {
setSystemLocaleLegacy(conf, new Locale(lang.toLowerCase()));
}
res.updateConfiguration(conf, dm);
//startActivity(new …Run Code Online (Sandbox Code Playgroud) val string = "5 kg rice 2 kg wheat 3 kg Soya"
Run Code Online (Sandbox Code Playgroud)
上面的字符串中是否有高阶函数来计算字符串“kg”?