接上一篇,今天把搜索的代码放上去了。效果图如下。
MainActivity.java
package com.stk.afinder;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.Button;
import android.view.View;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.Toast;
import android.widget.EditText;
import java.util.ArrayList;
import java.io.File;
public class MainActivity extends Activity {
static private ArrayList<String> search_result = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list = (ListView) findViewById(R.id.result_list);
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,search_result));
Button searchBn = (Button) findViewById(R.id.search_bn);
searchBn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (search_result != null) {
search_result.clear();
}
EditText et = (EditText) findViewById(R.id.file_name_edit);