發表文章

目前顯示的是有「Android Studio」標籤的文章

Android studio 連接 SQL Server

 Android studio 連接 SQL Server 前言 我們使用JTDS與SQL Server做連線 去 下載JTDS.jar 放入Android studio libs裡(本篇使用1.2.8) 如果不知道如何導入.jar檔可以參考 Android Studio JAR/AAR檔打包、導入 獲得SQL Server資料 初始化 JTDS driver String driverName = "net.sourceforge.jtds.jdbc.Driver" ; Class. forName ( driverName driverName) ; 與SQL Server連線並獲取資料 conn = DriverManager. getConnection ( url , username , password ) ; //(url, 帳號 , 密碼 ) ps = conn.prepareStatement( "SELECT [table1].[ID],[table1].[Name],[table1].[Color] \n " + "WHERE [table1]" ) ; //SQL 搜尋語法 rs = ps.executeQuery() ; // 查詢資料 while (rs.next()) // 用 while 迴圈列出每行資料 { String Name = rs.getString( "Name" ) ; // 獲得紀錄每行資料 } 記錄下表table1 Name資料列內容 table1的表格 ID Name Color 1 Red #FF0000 2 G...

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...