2013-12-14 50 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

歡迎您:)如果對您有幫助,您應該注意/接受答案。 –