我正使用 ListView 来列出文件夹中的全部图片, 然后在 ListTroundClick 上, 我开始另一个活动, 将名字传给它并在下一个活动中在 Webview 中显示图片 。 即使图片在文件夹中, 并且 ListView 读得正确, WebView 也不会显示它, 任何想法吗?
这是我的代码:
public class Dives extends ListActivity {
private File currentDir;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
currentDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "DivePlanner" + File.separator);
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return (name.endsWith("png") || name.endsWith("jpg") || name.endsWith("jpeg") || name.endsWith("PNG") || name.endsWith("JPG") || name.endsWith("JPEG"));
时 时
时 时;
String[] values = currentDir.list(filter);
if (values == null)
{
Toast.makeText(getApplicationContext(), "Error", 500).show();
时 时
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
getListView().setBackgroundDrawable(getResources().getDrawable(R.drawable.diver));
时 时
@Override
protected void onListItemClick(ListView list, View v, int position, long id) {
list.setBackgroundDrawable(getResources().getDrawable(R.drawable.diver));
String item = (String) getListAdapter().getItem(position);
Intent myIntent = new Intent(this, DisplayDive.class);
Bundle B = new Bundle();
B.putString("jmeno", item);
myIntent.putExtras(B);
this.startActivity(myIntent);
时 时
时 时
以显示文件, 在 OnClick 中开始显示文件的另一个活动 :
public class DisplayDive extends Activity {
/** Called when the activity is first created. */
WebView myWebView;
String jmeno;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.table);
Bundle extras = this.getIntent().getExtras();
if(extras!=null) jmeno = extras.getString("jmeno");
myWebView = (WebView)findViewById(R.id.myWebView);
myWebView.setInitialScale(100);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.loadUrl(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + "DivePlanner" + File.separator + jmeno);
时 时
时 时
WebView 最终总是有页面不可用 / mant/ sdcard/ DivePlanner/ file_ name.jpeg 。
还有一件事:我不知道为什么电话内存的文件夹应该放在SDCard上? (我把一些程序上的笔筒导出到这个文件夹,让我惊讶的是,文件夹不是在SD卡上创建的,而是在电话上创建的)