android--Fast Search for Mobile file engine applet (Files I/O)

Source: Internet
Author: User

The Main.xml code is as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G    T <tablelayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Android:orien                tation= "vertical" > <TableRow> <textview android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Please enter keywords to search:"/> <edittex T android:id= "@+id/edit" android:layout_width= "120px" android:layout_height= "        Wrap_content "/> </TableRow> </TableLayout> <button android:id=" @+id/btn_search " Android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "Search"/> <T Extview android:id= "@+Id/info "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "/></linearlayout> 
The. Java program is as follows:

Package Org.lxh.demo;import Java.io.file;import Android.app.activity;import android.app.alertdialog;import Android.app.dialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.View; Import Android.view.view.onclicklistener;import Android.view.view.onfocuschangelistener;import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;public class Hello extends Activity {private Button search = null;private TextView info = null;private EditText edit = null;public void OnCreate (Bund Le Savedinstancestate) {super.oncreate (savedinstancestate);//life cycle Method Super.setcontentview (R.layout.main); Set the layout manager to use This.edit = (EditText) Super.findviewbyid (r.id.edit); this.info = (TextView) Super.findviewbyid (r.id.info) ; this.search = (Button) Super.findviewbyid (R.id.btn_search); This.search.setOnClickListener (new OnClick ());} Private class OnClick implements Onclicklistener {public void onclick (View arg0) {String keyWords = Hello.this.edit.getTex T (). toString (); if (Keywords.equals ("")) {Hello.this.info.setText ("Please enter keywords! ");} else {Hello.this.info.setText (Searchfile (KeyWords));}} Private Charsequence Searchfile (string keyWords) {string result = ""; file[] Files = new file ("/"). Listfiles ();//Gets All files for (file f:files) {if (F.getname (). IndexOf (KeyWords) >= 0) {//filename match Result + = F.getpath () + "\ n";}} if (Result.equals (")) {result =" File not found! ";} return result;}}}

Run as follows:



android--Fast Search for Mobile file engine applet (Files I/O)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.