Android quick search mobile phone file Engine

Source: Internet
Author: User
1 package com. turboradio. googlesdk;
2
3 import java. io. File;
4
5 import android. app. Activity;
6 import android. OS. Bundle;
7 import android. view. View;
8 import android. widget. EditText;
9 import android. widget. TextView;
10
11 public class Ex_4_11 extends Activity {
12 private EditText mKeyword;
13 private TextView mResult;
14 @ Override
15 protected void onCreate (Bundle savedInstanceState ){
16 super. onCreate (savedInstanceState );
17 setContentView (R. layout. ex_4_11 );
18 mKeyword = (EditText) findViewById (R. id. et );
19 mResult = (TextView) findViewById (R. id. text2 );
20
21}
22 /**
23 * Add button listening
24 */
25 public void searchListener (View v ){
26/** get the entered keyword **/
27 String keyword = mKeyword. getText (). toString ();
28 if (mKeyword. equals ("")){
29 mResult. setText ("do not enter blank keywords !! ");
30} else {
31 mResult. setText (searchFile (keyword ));
32}
33}
34/** search file Method **/
35 private String searchFile (String keyword ){
36 String result = "";
37 File [] files = new File ("/"). listFiles ();
38 for (File f: files ){
39 if (f. getName (). indexOf (keyword) = 0 ){
40 result + = f. getPath () + "\ n ";
41}
42}
43 if (result. equals (""))
44 result = "file not found !! ";
45 return result;
46}
47}

Ex_4_11.xml

1 <? Xml version = "1.0" encoding = "UTF-8"?>
2 <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
3 android: layout_width = "fill_parent"
4 android: layout_height = "fill_parent"
5>
6 <TextView
7 android: id = "@ + id/text1"
8 android: layout_width = "wrap_content"
9 android: layout_height = "wrap_content"
10 android: text = "input Keyword :"
11 android: paddingTop = "10dip"
12/>
13 <EditText
14 android: id = "@ + id/et"
15 android: layout_width = "match_parent"
16 android: layout_height = "wrap_content"
17 android: layout_toRightOf = "@ id/text1"
18 android: layout_alignTop = "@ id/text1"
19/>
20 <Button
21 android: id = "@ + id/button"
22 android: layout_width = "wrap_content"
23 android: layout_height = "wrap_content"
24 android: text = "Search"
25 android: layout_below = "@ id/et"
26 android: layout_alignLeft = "@ id/et"
27 android: onClick = "searchListener"
28/>
29 <TextView
30 android: id = "@ + id/text2"
31 android: layout_width = "fill_parent"
32 android: layout_height = "wrap_content"
33 android: layout_below = "@ id/button"
34 android: layout_alignParentLeft = "true"
35/>
36 </RelativeLayout>

Related Article

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.