갤러리의 경우 OnItemSelected Listener의 마커를 변경하려고합니다. 실제로 항목 목록과 갤러리에서 존경받는 항목의 마커를 보여주는지도가 있습니다 .i 갤러리에서 항목을 선택할 때 마커 (파란색에서 주황색)를 변경하고 싶습니다. 어떻게 할 수 있습니까?이 링크의 코드로 마커를 변경하면 마커를 변경했습니다.OnItemSelected의 마커를 변경하는 방법
http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F7038636%2Fhow-to-change-the-marker-for-the-overlay-on-tap-for-android&sa=D&sntz=1&usg=AFQjCNFOnFJHf-f0nTea-a3Rs5hpx4U1IQ onItemSelected Listener.please를 사용하여 동일한 방법으로 제안 할 수 있습니다.
나는 전체 코드를 제공 할 수 없지만 여기까지 내가 지금까지해온 것을 이해할 수있는 몇 가지가있다. 여기
오버레이 클래스입니다 : 당신은 이미 당신이 마커를 클릭하면 색상을 변경 마커를 구현 한 경우import java.util.ArrayList;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.widget.Gallery;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
/**
* @author Anshul
* class is responsible for creating overlays on the map
*
*/
public class SearchCarOverlay extends ItemizedOverlay<OverlayItem> {
Context context;
MapView map;
Gallery mapGallery;
private Drawable heart = null;
private ArrayList<CustomItem> aList = null;
public SearchCarOverlay(Cursor cursor, Context m, MapView mView,
Gallery carGallery) {
// super(boundCenterBottom(cursor));
super(null);
context = m;
this.map = mView;
this.mapGallery = carGallery;
aList = new ArrayList<CustomItem>();
addItemsToList(cursor);
populate();
}
/**
* @param cursor
* This method will add all the point to the list.
*/
private void addItemsToList(Cursor cursor) {
GeoPoint point = null;
if (cursor != null && cursor.getCount() > 0) {
cursor.moveToFirst();
do {
int lat = (int) (cursor.getDouble(cursor
.getColumnIndex("Latitude")) * 1000000);
System.out.println("checking for latitude and longitude*************"
+ lat);
int lng = (int) (cursor.getDouble(cursor
.getColumnIndex("Longitude")) * 1000000);
point = new GeoPoint(lat, lng);
aList.add(new CustomItem(point, "", "",
getMarker(R.drawable.heart_full), heart));
} while (cursor.moveToNext());
// map.getController().animateTo(point);
}
}
/**
* @param resource
* @return drawable
* for getting the map markers
*/
private Drawable getMarker(int resource) {
Drawable marker = context.getResources().getDrawable(resource);
marker.setBounds(0, 0, marker.getIntrinsicWidth(),
marker.getIntrinsicHeight());
boundCenter(marker);
return (marker);
}
@Override
protected CustomItem createItem(int i) {
return aList.get(i);
}
@Override
public int size() {
return aList.size();
}
@Override
protected boolean onTap(int index) {
mapGallery.setSelection(index);
return true;
}
void toggleHeart() {
CustomItem focus = (CustomItem) getFocus();
if (focus != null) {
focus.toggleHeart();
}
map.invalidate();
}
/*
public ArrayList<CustomItem> getListOfItems(){
return aList;
}*/
/**
* releases all the objects memory
*/
public void cleanUp(){
context = null;
map = null;
mapGallery = null;
heart = null;
}
}
class CustomItem extends OverlayItem {
Drawable marker = null;
boolean isHeart = false;
Drawable heart = null;
CustomItem(GeoPoint pt, String name, String snippet, Drawable marker,
Drawable heart) {
super(pt, name, snippet);
System.out.println(" CustomItem CONSTRUCTOR ");
this.marker = marker;
this.heart = heart;
}
@Override
public void setMarker(Drawable marker) {
System.out.println(" CustomItem setMarker ");
// setState(marker, android.R.attr.state_pressed);
}
@Override
public Drawable getMarker(int stateBitset) {
Drawable result = (isHeart ? heart : marker);
System.out.println(" CustomItem getMarker ");
setState(result, stateBitset);
return (result);
}
void toggleHeart() {
System.out.println(" CustomItem toggleHeart ");
isHeart = !isHeart;
}
}
`
and my fragment file which contains gallery and map
public class SearchCarsFragment extends Fragmnent implements OnItemClickListener, OnClickListener{
MapView mapView;
private Gallery carGallery;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup v, Bundle bundle) {
View view = inflater.inflate(R.layout.search_car_result, null);
headerText = (TextView)view.findViewById(R.id.frag_search_result);
carGallery = (Gallery)view.findViewById(R.id.car_gallery);
mapContainer = (LinearLayout)view.findViewById(R.id.search_map_container);
listOrMap = (Button)view.findViewById(R.id.frag_search_option);
helpButton = (Button)view.findViewById(R.id.frag_search_help);
inflaterForMap = inflater;
InitialiseMapView();
initialiseMapAndGallery();
listOrMap.setOnClickListener(this);
helpButton.setOnClickListener(this);
return view;
}
/**
* used to create map view everytime we come to Searchcars fragment
*/
private void InitialiseMapView() {
if(mapViewFrameLayout == null){
mapViewFrameLayout = (FrameLayout)inflaterForMap.inflate(R.layout.maps, null);
mapView = (MapView) mapViewFrameLayout.findViewById(R.id.carhomezone);
}else{
mapView = (MapView) mapViewFrameLayout.findViewById(R.id.carhomezone);
}
}
/**
* initialises the map and gallery in the screen
*/
private void initialiseMapAndGallery() {
dismissDialog();
cursor = DatabaseUtil.getInstance().getSortedCarResults(Constants.SORT_BY_DEFAULT);
if(cursor != null && cursor.getCount() > 0){
headerText.setText("Search Results ("+cursor.getCount()+")");
initialiseMap(cursor);
initialiseGallery(cursor);
}else{
System.out.println("problem in getting the data from the database");
}
}
/**
* @param cursor
* initialises the map for search results
*/
private void initialiseMap(Cursor cursor) {
InitialiseMapView();
mapContainer.addView(mapViewFrameLayout);
//GeoPoint point = null ;
searchCarOverlay = new SearchCarOverlay(cursor,SearchFragmentActivity.mContext,mapView,carGallery);
mapView.getOverlays().add(searchCarOverlay);
mapView.setSatellite(false);
//mapView.setStreetView(true);
MapController mc = mapView.getController();
mapView.setBuiltInZoomControls(true);
mc.setZoom(16);
//mapContainer.addView(mapView);
//mc.animateTo(point);
mapView.invalidate();
}
/**
* @param cursor
* initialises the gallery for search results
*/
private void initialiseGallery(Cursor cursor) {
carGallery.setAdapter(new CarGalleyAdapter(SearchFragmentActivity.mContext ,cursor));
carGallery.setOnItemClickListener(this);
carGallery.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
System.out.println(" onItem selected listenert is called"+position);
// here i need to right the code for changinh marker onItmeselected
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
System.out.println(" onNothingSelected selected listenert is called ");
}
});
}
코드를 제공하십시오. – Triode
제 코드를 편집하여 제게 해결책을 알려주십시오. – anshul
Android의 모든 마스터는 어디에 있습니까? – anshul