小编OkD*_*oid的帖子

android Spinner中的DataBinding错误

我试图设置与Android Spinner的双向绑定,但我收到以下错误.

引起:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误.****/数据绑定错误****msg:找不到属性'bind:selectedValue'的getter,android.widget.Spinner上的值类型为java.lang.String****\data binding error****

这是我的SpinnerBindingUtils

public class SpinnerBindingUtils {

    @BindingAdapter(value = {"bind:selectedValue", "bind:selectedValueAttrChanged"},
        requireAll = false)
    public static void bindSpinnerData(AppCompatSpinner pAppCompatSpinner, String newSelectedValue,
        final InverseBindingListener newTextAttrChanged) {
        pAppCompatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                newTextAttrChanged.onChange();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        if (newSelectedValue != null) {
            int pos = ((ArrayAdapter<String>) pAppCompatSpinner.getAdapter()).getPosition(newSelectedValue);
            pAppCompatSpinner.setSelection(pos, true);
        }
    }

    @InverseBindingAdapter(attribute = "bind:selectedValue",
        event = "bind:selectedValueAttrChanged")
    public static String captureSelectedValue(AppCompatSpinner pAppCompatSpinner) {
        return …
Run Code Online (Sandbox Code Playgroud)

android android-spinner kotlin android-databinding

5
推荐指数
1
解决办法
3186
查看次数

为什么我在 kotlin 中收到错误:变量期望?

我正在尝试编写一个函数来查找 kotlin 中的多数元素,但是当我编译代码时,我在以下行中收到可变预期错误

                   map[key]?.let{ value->
Run Code Online (Sandbox Code Playgroud)

下面是我正在尝试运行的函数。我是 Kotlin 新手,不确定为什么会收到此错误。

fun majorityElement(nums: IntArray): Int {
        HashMap<Int,Int>().let{ map ->
                nums.forEach{ key->        
                   map[key]?.let{ value->
                        map[key]=value+1
                    }?:map[key]=1

                }
                map.forEach{entry->
                    if(entry.value>nums.size/2){
                        return entry.key
                    }
                }
        }
        return -1
    }
Run Code Online (Sandbox Code Playgroud)

kotlin

2
推荐指数
1
解决办法
5710
查看次数

使用Espresso滚动回收器视图

我有一个异构的回收站视图,我试图将其滚动到位置30处的项目。我的测试通过了,但是我看不到屏幕实际在滚动。

onView(withId(R.id.content_view))
    .perform(RecyclerViewActions.scrollToPosition(30));
Run Code Online (Sandbox Code Playgroud)

这就是我要做的滚动。

android android-espresso android-recyclerview android-espresso-recorder

1
推荐指数
2
解决办法
2306
查看次数