亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android遍歷所有文件夾和子目錄搜索文件

 更新時(shí)間:2016年07月21日 14:55:04   作者:陳明元  
為了準(zhǔn)確搜索文件,大家可以采取什么方法查找文件,本文為大家介紹Android遍歷所有文件夾和子目錄實(shí)現(xiàn)文件搜索功能,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android遍歷所有文件夾和子目錄來搜索文件,供大家參考,具體內(nèi)容如下

java代碼:

import java.io.File;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ShuosouwenjianActivity extends Activity implements OnClickListener {

  
  
  private File file; 
  private String path; 
  private String info; 
  private String key; //關(guān)鍵字 
  private TextView result; // 顯示結(jié)果 
  private EditText et; // 編輯view 
  private Button search_btn; // button view 

 

  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   
    result = (TextView)findViewById(R.id.TextView_Result); 
    et = (EditText)findViewById(R.id.key); 
    search_btn = (Button)findViewById(R.id.button_search); 
    // file = new File(Environment.getExternalStorageDirectory().getPath()); 
    file = new File("/sdcard/"); 
    info = getString(R.string.info); 
     
    search_btn.setOnClickListener(this); 
  } 
 
   
  @Override 
  public void onClick(View v) { 
    // TODO Auto-generated method stub 
    path = ""; 
    result.setText(""); 
    key = et.getText().toString(); 
    BrowserFile(file); 
  } 
   
  public void BrowserFile(File fileold) { 
    if (key.equals("")) { 
      Toast.makeText(this, getString(R.string.pleaseInput), Toast.LENGTH_LONG).show(); 
    } else { 
     search(fileold); 
      if (result.getText().equals("")) { 
        Toast.makeText(this, getString(R.string.notFound), Toast.LENGTH_SHORT).show(); 
      } 
    } 
  } 
 
 private void search(File fileold)

  {

   try{

 File[] files=fileold.listFiles();

 if(files.length>0)

 {

   for(int j=0;j<files.length;j++)

   {

  if(!files[j].isDirectory())

  {

  if(files[j].getName().indexOf(key)> -1)

  {

  path += "\n" + files[j].getPath(); 
    result.setText(info+path);


     //shuju.putString(files[j].getName().toString(),files[j].getPath().toString());

  }

  }

  else{

  this.search(files[j]);

  }

   }

 }

 }

   catch(Exception e)

   {

   

   }

  }

}

MAIN.XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  android:orientation="vertical" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:id="@+id/widget0" 
  > 
   
<Button 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:id="@+id/button_search" 
  android:layout_x="253px" 
  android:layout_y="5px" 
  android:text="@string/toSearch" 
/> 
<EditText 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:id="@+id/key"
  android:text="821077962.db" 
 
 
/> 

<TextView 
  android:layout_width="fill_parent" 
  android:layout_height="370px" 
  android:id="@+id/TextView_Result" 
  android:layout_x="0px" 
  android:layout_y="60px" 
/> 
</AbsoluteLayout>

strings.xml代碼:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
  <string name="hello">Hello World, Activity07!</string> 
  <string name="app_name">文件搜索</string> 

  <string name="toSearch">搜索</string> 
  <string name="info">系統(tǒng)SDCard目錄文件路徑:\n</string> 
  <string name="pleaseInput">請(qǐng)輸入關(guān)鍵字!</string> 
  <string name="notFound">SD卡中沒有相關(guān)文件!!</string> 
  <string name="pathError">讀取路徑出錯(cuò)!!</string> 
</resources> 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Flutter路由守衛(wèi)攔截的實(shí)現(xiàn)

    Flutter路由守衛(wèi)攔截的實(shí)現(xiàn)

    路由守衛(wèi)攔截最常見的應(yīng)用場(chǎng)景就是對(duì)用戶數(shù)據(jù)權(quán)限的校驗(yàn),本文主要介紹了Flutter路由守衛(wèi)攔截的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android實(shí)現(xiàn)字幕滾動(dòng)的方法

    Android實(shí)現(xiàn)字幕滾動(dòng)的方法

    這篇文章主要介紹了Android實(shí)現(xiàn)字幕滾動(dòng)的方法,很實(shí)用的功能,需要的朋友可以參考下
    2014-07-07
  • 圖文詳解自定義View視圖的屬性及引用

    圖文詳解自定義View視圖的屬性及引用

    這篇文章主要介紹了圖文詳解自定義View視圖的屬性及引用,由于Android自帶的視圖無法滿足自己需求,又或者美觀度不夠自己的要求,我們就要自來親自設(shè)計(jì)自己的視圖,需要的朋友可以參考下
    2023-04-04
  • 詳解Android studio ndk配置cmake開發(fā)native C

    詳解Android studio ndk配置cmake開發(fā)native C

    這篇文章主要介紹了詳解Android studio ndk配置cmake開發(fā)native C,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-09-09
  • Android仿優(yōu)酷視頻的懸浮窗播放效果

    Android仿優(yōu)酷視頻的懸浮窗播放效果

    這篇文章主要介紹了Android仿優(yōu)酷視頻的懸浮窗播放效果,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Android自定義橡皮擦效果

    Android自定義橡皮擦效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義橡皮擦效果,橡皮擦擦圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android開發(fā)之AlarmManager的用法詳解

    Android開發(fā)之AlarmManager的用法詳解

    這篇文章主要介紹了Android開發(fā)之AlarmManager的用法,是Android應(yīng)用開發(fā)中非常實(shí)用的技能,需要的朋友可以參考下
    2014-07-07
  • Android仿網(wǎng)易新聞圖片詳情下滑隱藏效果示例代碼

    Android仿網(wǎng)易新聞圖片詳情下滑隱藏效果示例代碼

    這篇文章主要給大家介紹了關(guān)于利用Android如何仿網(wǎng)易新聞圖片詳情下滑隱藏效果的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07
  • android activity設(shè)置無標(biāo)題實(shí)現(xiàn)全屏

    android activity設(shè)置無標(biāo)題實(shí)現(xiàn)全屏

    本文將詳細(xì)介紹Android如何設(shè)置Activity全屏和無標(biāo)題的實(shí)現(xiàn)方法,需要的朋友可以參考下
    2012-12-12
  • Android菜單的定義及ActionBar的實(shí)現(xiàn)

    Android菜單的定義及ActionBar的實(shí)現(xiàn)

    本篇文章主要介紹了Android菜單的定義及ActionBar的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-08-08

最新評(píng)論