發表文章

Android Studio .csv檔讀寫

圖片
 Android Studio .csv檔讀寫 可以先參考 Android Studio 檔案讀寫 內有寫關於Android Studio讀寫檔案基礎介紹 本次使用ArrayList存放CSV資料,使用RecyclerView顯示資料 建立ArrayList Data Model 新增DataModel的Java class public class DataModel { private String ID ; private String Name ; private String Score ; public DataModel (String ID , String Name , String Score){ this . ID = ID ; this . Name = Name ; this . Score = Score ; } public String getID (){ return ID ; } public String getName (){ return Name ; } public String getScore (){ return Score ; } } 並在Activity內宣告ArrayList ArrayList<DataModel> datalist = new ArrayList<>() 建立RecyclerView & Adapter 在建立Adapter之前可以先建立ViewHolder public class ViewHolder extends RecyclerView.ViewHolder { public TextView idtext , nametext , scoretext ; public ViewHolder ( @NonNull View itemView) { super (itemView) ; i...

Android Studio 寫入檔案PC無法顯示

Android Studio 寫入檔案PC無法顯示 寫入檔案後需要使系統重新掃描檔案 可以使用以下方式 1. Intent intent = new Intent(Intent. ACTION_MEDIA_SCANNER_SCAN_FILE ) ; Uri uri = Uri. fromFile (newTextFile) ; intent.setData(uri) ; context .sendBroadcast(intent) ; 2. MediaScannerConnection. scanFile ( context ,new String[]{file.getAbsolutePath()} ,null,null ) ;

Android Studio 檔案讀寫

圖片
 Android Studio 檔案讀寫 讀寫權限 <uses-permission android :name ="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android :name ="android.permission.WRITE_EXTERNAL_STORAGE" /> 取得儲存路徑 getDataDirectory() 取得手機內存根目錄 getDownloadCacheDirectory() 取得手機暫存 getRootDirectory() 取得手機系統目錄 getExternalStorageDirectory() 取得手機外部儲存SD Card目錄 取得路徑的格式 getPath() 取得定義的路徑 getAbsolutePath() 取得絕對路徑 getCanonicalPath() 取得符合路徑規範的路徑 File file = new File( "TXT/./test.txt" ) ; Log. d ( "frilgetPath" , "==" +file.getPath()) ; Log. d ( "frilAbsolutePath" , "==" +file.getAbsolutePath()) ;...

Android Studio RecyclerView JSON API

圖片
 Android Studio RecyclerView JSON API AndroidManifest權限設定 在AndroidManifest中加入網路訪問權限> <uses-permission android :name ="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android :name ="android.permission.INTERNET" /> Layout activity_main <LinearLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" android :layout_height ="match_parent" android :orientation ="vertical" tools :context =".MainActivity" > <androidx.recyclerview.widget.RecyclerView android :id ="@+id/recyclerlist" android :layout_width ="match_parent" android :layout_height ="wrap_conte...

Android Studio多執行緒處理

圖片
 Android Studio多執行緒處理 Thread Java的標準執行續 如果需要長時間執行Thread會比較適合 無法直接與UI溝通,如果需要修改UI必須通過其他類別來設定 基本應用 第一種 與Runnable搭配使用 Thread mThread = new Thread( rnb ) ; mThread. start() ; private Runnable rnb = new Runnable () {      public void run ()      {           // 執行的動作      } } ; 第二種 建class繼承Thread private ...