2021-07-23 单选dialog

 itemArr.add(getResources().getStringArray(R.array.arr_2));

//itemArr是一个集合 
private void showListDialogText(final int pos, String title) {
        AlertDialog listDialogText = null;
        listDialogText = new AlertDialog.Builder(mContext).
                setTitle(title).setSingleChoiceItems(itemArr.get(pos), selval[pos], null)
                .setNegativeButton(getResources()
                        .getString(R.string.cancel), null).create();
        listDialogText.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                for (int i = 0; i < itemArr.get(pos).length; i++) {
                    listDialogText.getListView().setEnabled(false);//不能选中,无法操作dialog
                    listDialogText.getListView().getChildAt(i).setEnabled(false);
                }
            }
        });
        if (listDialogText != null) {
            listDialogText.show();
        }
    }
 <TimePicker
                android:id="@+id/tp_start_work"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:timePickerMode="spinner" />
//时间控件样式选择

<DatePicker

        android:id="@+id/date_picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@color/list_coler"
        android:calendarTextColor="@color/item_select_d"
        android:calendarViewShown="false"
        android:datePickerMode="spinner"></DatePicker>

 关于如何拿到安卓手机存储

//反射拿控件  AirSmallBoxView是空调控件
 Field seat_status_tv = AirSmallBoxView.class.getDeclaredField("seat_status_tv");
seat_status_tv.setAccessible(true);
TextView textView = (TextView)seat_status_tv.get(mAirSmallBoxView); // 获取textView实例
textView.getText();

//手机内部:APP目录下默认有两个文件夹,一个是cache,一个是files
//cache目录
cacheDir.absolutePath
//files目录
filesDir.absolutePath
//手机内部的APP目录怎么获取呢?
cacheDir.parent
filesDir.parent

//手机外部APP目录
//cache目录
externalCacheDir.absolutePath
//APP目录
externalCacheDir.parent


Environment.getDataDirectory():     /data
Environment.getRootDirectory():    /system
Environment.getDownloadCacheDirectory():     /cache
Environment.getExternalStorageDirectory():   /storage/emulated/0


//dp 转 px
/**
 * 返回你需要的值:如:这里你传20,单位你传dp,返回值就是你这个手机对应的20dp
 *
 * @param value 数据
 * @param unit  单位:dp为{@link TypedValue#COMPLEX_UNIT_DIP},
 *                  sp为{@link TypedValue#COMPLEX_UNIT_SP},
 *                  px为{@link TypedValue#COMPLEX_UNIT_PX},
 *              其它请看{@link TypedValue#applyDimension(int, float, DisplayMetrics)}
 * @return 具体长度数值
 */
public static float digitValue(final float value, final int unit) {
    return TypedValue.applyDimension(unit, value, Resources.getSystem().getDisplayMetrics());
}

 模拟点击按钮:海晨忆


Button btn1 = findViewById(R.id.btn1);
final Button btn2 = findViewById(R.id.btn2);
btn1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.v("wz","btn1");
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis()+100;
        float upX = btn2.getX()+50;
        float upY = btn2.getY()+50;
        MotionEvent obtainDown = MotionEvent.obtain(downTime, eventTime, ACTION_DOWN, upX, upY, 0);

        long downTime1 = SystemClock.uptimeMillis();
        long eventTime1 = SystemClock.uptimeMillis()+100;
        float upX1 = btn2.getX()+50;
        float upY1 = btn2.getY()+50;
        MotionEvent obtainUp = MotionEvent.obtain(downTime1, eventTime1, MotionEvent.ACTION_UP, upX1, upY1, 0);
        btn2.dispatchTouchEvent(obtainDown);
        btn2.dispatchTouchEvent(obtainUp);
        obtainDown.recycle();
        obtainUp.recycle();
        Log.v("wz","downTime:"+downTime+" ,eventTime:"+eventTime+" ,upX:"+upX+" ,upY:"+upY+" ,downTime1:"+downTime1+" ,eventTime1:"+eventTime1+" ,upX1:"+upX1+" ,upY1:"+upY1);
    }
});
btn2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Log.v("wz","btn2");
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值