小编Ash*_*lam的帖子

具有DataBinding的RecyclerView项Click侦听器

我已经使用baseadapter通过数据绑定实现了回收站视图,该适配器可处理任何布局项目的所有绑定。

我试图使用方法引用和侦听器绑定来实现每项单击侦听器,但是我无法做到这一点。

这是我的代码。您能给我一个示例,它是检测回收站视图中每个项目的简单方法,并且我想为每个项目添加单击侦听器以用于不同的目的。谢谢。

MyBaseAdapter

public abstract class MyBaseAdapter extends RecyclerView.Adapter<MyBaseAdapter.MyViewHold> {





public class MyViewHold extends RecyclerView.ViewHolder implements View.OnClickListener {

    public ViewDataBinding binding;
    Context context;

    public MyViewHold(ViewDataBinding binding) {

        super(binding.getRoot());
        this.binding = binding;

        context = binding.getRoot().getContext();
        binding.getRoot().setOnClickListener(this);



    }

    // Here BR.pojo must be matched to layout variable name
    //our layout variable was
    /*
     <variable
        name="pojo"
        type="com.durbinlabs.databinding.POJO"
        />
     */
    public void bind(Object obj) {
        binding.setVariable(BR.pojo, obj);
        binding.setVariable(BR.food, obj);


        binding.executePendingBindings();



    }


    @Override
    public void onClick(View view) {
        // for all view

    }




} …
Run Code Online (Sandbox Code Playgroud)

data-binding android android-recyclerview android-databinding

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

一次又一次地调用位置权限回调

我已经实现了运行时权限。出于测试目的,我拒绝了位置许可,然后我再次拒绝了“不再询问”复选框的许可。现在问题来了。OnRequestPermissionResult 被系统一次又一次地调用。为此,我无法在屏幕上正确显示对话框或小吃栏。这是我的实现。问题出在哪儿?

检查位置权限

override fun onResume() {
    super.onResume()

    if (checkLocationPermission())
        startLocationUpdates()

    updateUI()
}
Run Code Online (Sandbox Code Playgroud)

这是我的位置更新电话

@SuppressLint("MissingPermission")
private fun startLocationUpdates() {

    // Begin by checking if the device has the necessary location settings.
    mLocationSettingsClient.checkLocationSettings(mLocationSettingsRequest)
            .addOnSuccessListener(this, {
                mFusedLocationClient.requestLocationUpdates(mLocationRequest,
                        mLocationCallback, Looper.myLooper());
                updateUI()
            })
            .addOnFailureListener(this, {
                handlingLocationClientSettingsFailure(it)
            });


}

  private fun handlingLocationClientSettingsFailure(it: Exception) {
    val apiException = it as ApiException

    when (apiException.statusCode) {
        LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> {
            try {

                Lg.d(TAG, "Inside start location update method FAILURE: REQUIRED")

                // Show the dialog by calling startResolutionForResult(), and check …
Run Code Online (Sandbox Code Playgroud)

android runtime-permissions

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