English 中文(简体)
ListView 读取了文件, 但 WebView 将不会显示它
原标题:ListView reads the file, but WebView won t display it

我正使用 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卡上创建的,而是在电话上创建的)

问题回答

您需要为 Webview 附加方案以显示它 。

file:///mnt/sdcard/Dive.....

你凭什么认为档案在电话里?





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签