在下面的代码我想实现的follwwing浏览器代码http://www.remwebdevelopment.com/dev/a34/Directory-Browser-Application.html
我刚开空白文本视图在这里为ouptut和我没有看到browser.What我做错了这里
public class File_browse extends Activity {
private List<String> items = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_browse);
getFiles(new File("/").listFiles());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_file_browse, menu);
return true;
}
protected void onListItemClick(ListView l, View v, int position, long id){
int selectedRow = (int)id;
if(selectedRow == 0){
getFiles(new File("/").listFiles());
}else{
File file = new File(items.get(selectedRow));
if(file.isDirectory()){
getFiles(file.listFiles());
}else{
new AlertDialog.Builder(this)
.setTitle("This file is not a directory")
.setNeutralButton("OK", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int button){
//do nothing
}
}).show();
//Toast.makeText(this, "This file is not a directory" + position, Toast.LENGTH_SHORT).show();
}
}
}
private void getFiles(File[] files){
Toast.makeText(this, "In get files" , Toast.LENGTH_SHORT).show();
items = new ArrayList<String>();
items.add(getString(R.string.app_name));
for(File file : files){
items.add(file.getPath());
}
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,R.layout.file_list_row, items);
ArrayAdapter adp = new ArrayAdapter(File_browse.this, android.R.layout.simple_list_item_1);
ListView mainlist = null;
mainlist.setAdapter(adp);
mainlist.setTextFilterEnabled(true);
}
}
main.xml中
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<!-- <TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".File_browse" />-->
</RelativeLayout>
file_list_row.xml旁边activity_file_browse.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>