[問題] getResoures與context的問題
R.raw中已經放好一個JSON
要用的class跟Activity在同一個package
請問要怎麼去使用getResoures()
this dot下去後 只有getClass()這個比較像能叫用的
但是這時候this就會說 cannot be refenrces from a static context
對於context這塊真的很不熟悉
還請各位指點,感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.178.63
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1453961219.A.DCE.html
推
01/28 14:11, , 1F
01/28 14:11, 1F
→
01/28 14:11, , 2F
01/28 14:11, 2F
大概是這樣的~
/////// Activity ///////////////
CheckJSON.Check(this,string);
/////// Class CheckJSON ////////
public class CheckJSON {
public static double Check(Context context, String string){
double c = 0.0;
InputStream is =
context.getResources().openRawResource(R.raw.ca);
.......
}
→
01/28 14:53, , 3F
01/28 14:53, 3F
→
01/28 14:56, , 4F
01/28 14:56, 4F
→
01/28 14:56, , 5F
01/28 14:56, 5F
在這!!
public class SpotDetailActivity extends AppCompatActivity {
private class MyInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
public View getInfoWindow(Marker marker) {
CALL CHECK
}}}
※ 編輯: jiqian (42.73.178.63), 01/28/2016 14:58:14
→
01/28 15:03, , 6F
01/28 15:03, 6F
推
01/28 15:17, , 7F
01/28 15:17, 7F
→
01/28 15:18, , 8F
01/28 15:18, 8F
謝謝各位的幫忙,我在外面放個CONTEXT全域變數可以用了!!
※ 編輯: jiqian (42.73.178.63), 01/28/2016 16:17:19
→
01/31 06:59, , 9F
01/31 06:59, 9F