欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
修改Android資源瀏覽器
[打印本頁]
作者:
hongniu
時間:
2015-6-25 15:18
標題:
修改Android資源瀏覽器
工作后很多東西都是現用現學,不用就忘,如果不記錄一下估計有一天就歸零了。
從沒系統的學過android,都是偶爾看看書寫點Demo。最近項目上可能需要用到手持設備,所以復習一下。項目中設計到文件上傳的功能,這樣文件資源瀏覽器是必不可少的控件。先百度了一下找到一位CSDN猴子的代碼(
http://blog.csdn.net/x605940745/article/details/12580367
)照著模仿下基本的功能出來了。但是有些不完善的地方?此膌ayout與后臺代碼的ID都沒有對應上,想必這兩段的代碼非出自一個Demo吧!
首先說第一個問題:加載出來的子文件夾單擊沒有相應。實現使用ListView加載更多的xml布局。所有的觸發事件都有,加斷點就是不進啊。。。百度查了一下,后來找到了原因。問題出在ListView子控件上有ImageButton元素,這種情況下單擊ListView時子控件會首先獲得focus。所以導致單擊ListView無效。解決辦法吧ImageButton換成ImageView就OK了
第二個問題:只有返回home沒有返回上級菜單。這個比較簡單,只需要用File.getParentFile();就OK了,但要注意的是判斷是否為跟節點,因根節點在獲取夫級元素就會拋異常。
Layout(activity_documents_browser.xml)源碼:
<LinearLayout 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"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:orientation="vertical"
tools:context="com.tonfun.smapp.DocumentsBrowserActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="32dp" >
<ImageView
android:id="@+id/imageBt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:padding="3dp"
android:src="@drawable/img_back" />
<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:padding="3dp"
android:textColor="#fff" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#218fff" />
<ListView
android:id="@+id/listFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants" >
</ListView>
</LinearLayout>
Layout(activity_folder.xml)源碼
<?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="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="30dp" >
<ImageView
android:id="@+id/imageBt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:padding="2dp"
android:src="@drawable/img_home" />
<TextView
android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:padding="2dp"
android:textColor="#fff" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#fff" />
</LinearLayout>
后臺(JAVA)代碼 :
package com.tonfun.smapp;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class DocumentsBrowserActivity extends Activity {
private ListView listfile;
// 當前文件目錄
private String currentpath;
private TextView txt1;
private ImageView images;
private TextView textview;
private ImageView imagebt1;
private File fBeforePath;
private int[] img = { R.drawable.img_files, R.drawable.img_folder,
R.drawable.img_home };
private File[] files;
private SimpleAdapter simple;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_documents_browser);
listfile = (ListView) findViewById(R.id.listFile);
txt1 = (TextView) findViewById(R.id.txt1);
imagebt1 = (ImageView) findViewById(R.id.imageBt1);
init(Environment.getExternalStorageDirectory());
fBeforePath = Environment.getExternalStorageDirectory().getParentFile();
listfile.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
// 獲取單擊的文件或文件夾的名稱
String folder = ((TextView) arg1.findViewById(R.id.txt1))
.getText().toString();
try {
File filef = new File(currentpath + '/' + folder);
if (!filef.isFile()) {
init(filef);
} else {
if (filef.getName().lastIndexOf('.') >= 0) {
Toast.makeText(
DocumentsBrowserActivity.this,
"擴展名:"
+ filef.getName().substring(
filef.getName()
.lastIndexOf('.'),
filef.getName().length())
+ ";絕對路徑:"
+ filef.getAbsolutePath(),
Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
// 回根目錄
imagebt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// init(Environment.getExternalStorageDirectory());
if (!fBeforePath.getAbsolutePath().equals("/")) {
init(fBeforePath);
} else {
Toast.makeText(DocumentsBrowserActivity.this, "提示:已為頂級目錄!",
Toast.LENGTH_SHORT).show();
}
}
});
}
// 界面初始化
public void init(File f) {
if (Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED)) {
// 獲取SDcard目錄下所有文件名
fBeforePath = f.getParentFile();
files = f.listFiles();
if (!files.equals(null)) {
currentpath = f.getPath();
try {
txt1.setText("當前目錄為:" + f.getPath());
} catch (Exception ex) {
}
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (int i = 0; i < files.length; i++) {
Map<String, Object> maps = new HashMap<String, Object>();
if (files[i].isFile())
maps.put("image", img[0]);
else
maps.put("image", img[1]);
maps.put("filenames", files[i].getName());
list.add(maps);
}
simple = new SimpleAdapter(this, list,
R.layout.activity_folder, new String[] { "image",
"filenames" }, new int[] { R.id.imageBt1,
R.id.txt1 });
listfile.setAdapter(simple);
}
} else {
System.out.println("該文件為空");
}
}
}
復制代碼
不貼下載連接了,著急會宿舍睡覺 (~﹃~)~zZ
忘記貼效果圖了(/ □ \)。。。
作者:
absflash
時間:
2015-7-5 08:34
朋友可接觸過安卓手機的藍牙串口調試助手,我想讓藍牙串口助手收到某一代碼后 觸發手機震動或聲音報警,朋友看是否有可行性,,,,主要是要修改一下藍牙調試助手源碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1