我創建的谷歌地圖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顯示空指針exeptionfor (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>
提前感謝任何幫助。
非常感謝。我會找到另一種方式。 – ajkala
歡迎您:)如果對您有幫助,您應該注意/接受答案。 –