Android 動態改變 Shape Drawable 顏色:獲取 ShapeDrawable 修改 Paint
XML 定義 <shape xmlns:android=https://schemas.android.com/apk/res/android andro
Android 登入頁面跳轉失效?Intent 寫法錯誤導致無法啟動目標 Activity
問題現象 輸入正確密碼點擊登入按鈕後,預期跳轉至新 Activity,但畫面無反應、無報錯。程式碼如下: { if (locker.e
Android 動態獲取 Drawable 資源 ID:getResources().getIdentifier()
需求 圖片資源命名規則 d002_p001 ~ d002_p050,需動態構建陣列而非手寫 50 個常數。 代碼實現 int[] images = new i
iOS UITableView 傳遞 Cell 資料至 Detail View Controller 完整實作
核心需求 在 UITableView 的 didSelectRowAtIndexPath 中,取得當前選中行對應的模型資料(如電影標題),並傳遞給即將 Push
iOS 兩個 ViewController 傳值:臨時變量無法回傳,需用 Delegate 或 Block
問題場景 A 控制器 present B 控制器,B 輸入資料後需回傳給 A。嘗試用共享模型物件 test *t 但 A 收不到更新。 原因 B 中 Exam
iOS 子視圖控制器導航失效:需透過父視圖控制器 Push
問題 將 EventNameViewController 的 view 作為子視圖加入父視圖,其內部按鈕呼叫 pushViewController 無效果。
Android 檢查 View 背景是否為指定 Drawable:直接比較 Drawable 物件
錯誤代碼 Drawable d = v1.getBackground(); if (d.getConstantState() == getResources()
Android 從 SD 卡載入背景資源:BitmapDrawable 包裝 Bitmap
需求 按鈕背景資源來自 SD 卡路徑,而非 R.drawable。 代碼實現 Button btn = new Button(context); String
Java 聊天程式 Bug:客戶端訊息重複顯示、服務端廣播邏輯錯誤
現象 開啟 3 個客戶端 A、B、C,A 發送訊息,B 顯示 3 次相同訊息,C 無反應。 客戶端問題 // 客戶端讀取執行緒 while (flag) {
Android 根據日期計算星期幾:Calendar + SimpleDateFormat
核心代碼 Calendar cal = Calendar.getInstance(); cal.set(2013, Calendar.MAY, 7); // 月
i.MX6 U-Boot 啟動 Android 失敗:MMC 初始化錯誤與分區表問題
錯誤日誌關鍵點 Card did not respond to voltage select! mmc3 init failed Bad partition i
Android LinearLayout 按鈕對齊:RelativeLayout 容器配合 alignParentLeft/Right
問題 水平 LinearLayout 中兩個按鈕,左邊一個靠左,右邊一個靠右,中間空白。 解決:改用 RelativeLayout <RelativeL
Android SQLite 查詢崩潰:資料表名稱拼寫錯誤導致 no such table
錯誤堆疊 android.database.sqlite.SQLiteException: no such table: mycontacts (code 1)
Android 監聽其他 App 背景音樂播放狀態:Visualizer 頻譜分析曲線救國
困境 需求:偵測**其他 App** 是否正在播放音樂(播放 vs 暫停/停止),以決定自家功能行為。 官方 API 僅提供 AudioManager.isMu
Android SQLite 避免重複插入:唯一索引 + INSERT OR REPLACE
方案一:資料庫層面約束(最可靠) // 建表時加入唯一索引 CREATE TABLE contacts ( id INTEGER PRIMARY KEY
Android 重新啟動 Activity 觸發 onCreate:使用 Intent 搭配 Flags
標準重啟代碼 Intent intent = getIntent(); finish(); startActivity(intent); 避免動畫閃爍 Int
iOS NSUserDefaults 檢查用戶名:邏輯判斷搞反導致永遠進入 else
錯誤代碼 if ([defaults objectForKey:@username] != nil) { // 這裡意圖:沒有用戶名才顯示登入頁
iOS UILabel 固定寬度數字格式:自訂方法補零對齊
需求 數字顯示為固定寬度,前面補零: 輸入: 10, 100, 1000, 2345565 輸出: 00010.0, 00100.0, 01000.0, 234