Re: [問題] 關於 Widget 傳值
如果我要先學習用Handler去寫SharedPreferences接收可行嗎?
因為我一直接收不到傳過來的值,不知道哪裡有錯
程式碼如下:
final String mPerfName = "com.CountDownActivity";
TextView mTextView = (TextView) CountDownActivity.this
.findViewById(R.id.result);
SharedPreferences.Editor prefs = CountDownActivity.this
.getSharedPreferences(mPerfName, 0).edit();
prefs.putString("DAT" +h, mTextView.getText()
.toString());
prefs.putLong("HH" , h);
prefs.commit();
在widget接收:
SharedPreferences prefs = context.getSharedPreferences("DAT",
Context.MODE_PRIVATE);
SharedPreferences h = context.getSharedPreferences("HH", 0);
views.setTextViewText(R.id.T1, ""+prefs.getLong("DAT",0));
appWidgetManager.updateAppWidget(appWidgetId,views);
請問我的方法用對了嗎?widget的執行結果只會顯示0
麻煩大大解惑了感恩!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.33.134.136
推
11/20 19:21, , 1F
11/20 19:21, 1F
→
11/20 19:30, , 2F
11/20 19:30, 2F
推
11/20 19:33, , 3F
11/20 19:33, 3F
→
11/20 19:33, , 4F
11/20 19:33, 4F
→
11/20 19:34, , 5F
11/20 19:34, 5F
推
11/20 19:38, , 6F
11/20 19:38, 6F
→
11/21 16:31, , 7F
11/21 16:31, 7F
→
11/21 16:44, , 8F
11/21 16:44, 8F
→
11/21 16:45, , 9F
11/21 16:45, 9F
→
11/21 16:49, , 10F
11/21 16:49, 10F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 3 之 4 篇):