第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訪問 TimePickerDialog 的 NumberPicker 對象而不是

訪問 TimePickerDialog 的 NumberPicker 對象而不是

阿晨1998 2023-10-13 09:35:16
我正在嘗試創(chuàng)建一個具有小時和分鐘的自定義間隔的自定義,并設(shè)法通過使用此問題的TimePickerDialog答案來解決它。問題是 Android Studio 顯示以下警告:不支持通過反射訪問內(nèi)部 API,并且可能無法在所有設(shè)備上或?qū)砉ぷ?。使用反射訪問隱藏/私有的 Android API 并不安全;它通常無法在其他供應(yīng)商的設(shè)備上運(yùn)行,并且可能會突然停止工作[...]問題在第一行:Class<?> classForid = Class.forName("com.android.internal.R$id");Field timePickerField = classForid.getField("timePicker");TimePicker mTimePicker = findViewById(timePickerField.getInt(null));Field minuteField = classForid.getField("minute");Field hourField = classForid.getField("hour");NumberPicker minutePicker = mTimePicker.findViewById(minuteField.getInt(null));NumberPicker hourPicker = mTimePicker.findViewById(hourField.getInt(null));我需要一些訪問這兩個NumberPicker對象的替代方法。
查看完整描述

1 回答

?
holdtom

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個贊

我通過使用找到了解決方案Resources.getSystem().getIdentifier()。


代碼現(xiàn)在看起來像這樣:


TimePicker timePicker = findViewById(Resources.getSystem().getIdentifier(

    "timePicker", 

    "id", 

    "android"

));


NumberPicker minutePicker = timePicker.findViewById(Resources.getSystem().getIdentifier(

    "minute", 

    "id", 

    "android"

));


NumberPicker hourPicker = timePicker.findViewById(Resources.getSystem().getIdentifier(

    "hour", 

    "id", 

    "android"

));


查看完整回答
反對 回復(fù) 2023-10-13
  • 1 回答
  • 0 關(guān)注
  • 119 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號