当前位置: 代码迷 >> Android >> 遍历android源目录的简单资源查看器
  详细解决方案

遍历android源目录的简单资源查看器

热度:88   发布时间:2016-05-01 20:19:25.0
遍历android根目录的简单资源查看器

效果如图:

package com.txl.sua;import java.io.File;import java.util.List;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.ArrayAdapter;import android.widget.TextView;public class FileListAdapter extends ArrayAdapter<File> {	public FileListAdapter(Context context, int Resource, List<File> objects) {		super(context, Resource, objects);	}	@Override	public View getView(int position, View convertView, ViewGroup parent) {		TextView view = (TextView) super.getView(position, convertView, parent);		File file = getItem(position);		if (position == 0)			view.setText(view.getResources().getString(R.string.current_folder)					+ file.getAbsolutePath());		else if (position == 1 && !isRoot())			view.setText(R.string.to_parent_folder);		else			view.setText(file.getName());		return view;	}	public boolean isRoot() {		return getItem(0).getParent() == null;	}}

?

package com.txl.sua;import java.io.File;import java.io.FileFilter;import java.util.ArrayList;import java.util.List;import android.app.ListActivity;import android.os.Bundle;import android.view.KeyEvent;import android.view.View;import android.widget.ListView;public class SearchUpdateApkActivity extends ListActivity {	private FileListAdapter fileList;	@Override	protected void onCreate(Bundle savedInstanceState) {		super.onCreate(savedInstanceState);		fill(new File("/"));	}	@Override	public boolean onKeyDown(int keyCode, KeyEvent event) {		if (keyCode == KeyEvent.KEYCODE_BACK && !fileList.isRoot()) {			fill(fileList.getItem(1));			return true;		}		return super.onKeyDown(keyCode, event);	}	@Override	protected void onListItemClick(ListView l, View v, int position, long id) {		File file = fileList.getItem(position);		if (file.isDirectory())			fill(file);	}	private static final FileFilter IMAGES_FILTER = new FileFilter() {		public boolean accept(File file) {			return file.isDirectory()					|| file.getName().matches("^*.*$");// ("^.*?\\.(jpg|png|bmp|gif)$")		}	};	private void fill(File folder) {		List<File> files = new ArrayList<File>();		files.add(folder);		if (folder.getParentFile() != null)			files.add(folder.getParentFile());		for (File file : folder.listFiles(IMAGES_FILTER)) {			files.add(file);		}		fileList = new FileListAdapter(this, R.layout.file_row, files);		setListAdapter(fileList);	}}

?

<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/text1"    android:layout_width="fill_parent"    android:layout_height="wrap_content" />
  相关解决方案