2013-12-14 49 views
0

我创建的谷歌地图API V2一个应用基础水平的ListView

我想提出一个horizontal list view包含image,从SD卡获取,到信息窗口 有我的C ustomwindow adapter class

class CustomInfoWindowAdapter implements InfoWindowAdapter { 

    private final View mWindow; 
    private final View mContents; 
    LinearLayout myGallery; 

    CustomInfoWindowAdapter() { 
     mWindow = getLayoutInflater().inflate(R.layout.custom_info_window, 
       null); 
     mContents = getLayoutInflater().inflate(
       R.layout.custom_info_contents_with_listview, null); 
    } 

    @Override 
    public View getInfoWindow(Marker marker) { 

     render(marker, mWindow); 
     return mWindow; 
    } 

    @Override 
    public View getInfoContents(Marker marker) { 

     render(marker, mContents); 
     return mContents; 
    } 

    private void render(Marker marker, View view) { 
     int badge = 0; 

     myGallery = (LinearLayout) findViewById(R.id.mygallery); 

     // get file from sd card 
     String ExternalStorageDirectoryPath = Environment 
       .getExternalStorageDirectory().getAbsolutePath(); 
     String targetPath = ExternalStorageDirectoryPath + "/DCIM/Camera"; 

     File targetDirector = new File(targetPath); 

     File[] files = targetDirector.listFiles(); 

     if (marker.equals(listMarkers.get(0))) { 
      for (File file : files) { 
         myGallery.addView(insertPhoto(file.getAbsolutePath())); 
      } 
     } 

     String title = marker.getTitle(); 
     TextView titleUi = ((TextView) view.findViewById(R.id.title)); 
     if (title != null) { 

      SpannableString titleText = new SpannableString(title); 
      titleText.setSpan(new ForegroundColorSpan(Color.RED), 0, 
        titleText.length(), 0); 
      titleUi.setText(titleText); 
     } else { 
      titleUi.setText(""); 
     } 

     String snippet = marker.getSnippet(); 
     TextView snippetUi = ((TextView) view.findViewById(R.id.snippet)); 
     if (snippet != null && snippet.length() > 12) { 
      SpannableString snippetText = new SpannableString(snippet); 
      snippetText.setSpan(new ForegroundColorSpan(Color.MAGENTA), 0, 
        10, 0); 
      snippetText.setSpan(new ForegroundColorSpan(Color.BLUE), 12, 
        snippet.length(), 0); 
      snippetUi.setText(snippetText); 
     } else { 
      snippetUi.setText(""); 
     } 
    } 
} 

当我运行在

代码,LOCAT显示空指针exeption
for (File file : files) { 
          myGallery.addView(insertPhoto(file.getAbsolutePath())); 

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:orientation="vertical"> 

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <LinearLayout 
     android:id="@+id/mygallery" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     /> 
</HorizontalScrollView> 

提前感谢任何帮助。

回答

2

现在你有一个NullPointerException,但即使你将所有的图像放入这InfoWindow布局,你将无法滚动它,因为InfoWindow是不真实的看法。这只是一个呈现SurfaceView。所以你不能在其上应用onTouchonClick事件。

Google Docshttps://developers.google.com/maps/documentation/android/marker#info_windows

注意:绘制的信息窗口不是实时取景。在返回 时,视图是 呈现为图像(使用View.draw(Canvas))。这意味着对视图的任何后续更改都不会被地图上的信息窗口反映出来。稍后要更新信息窗口 (例如,在图像加载完成后),请拨打showInfoWindow()。此外,信息窗口将不考虑典型的用于诸如触摸或手势事件的普通视图的交互性 中的任何一个。但是,您可以在整个信息窗口中收听一般性点击事件 ,如 所述。

+0

非常感谢。我会找到另一种方式。 – ajkala

+0

欢迎您:)如果对您有帮助,您应该注意/接受答案。 –