Hi CommonsWare
I saw your code, it works fine, in your example.
but I have a mapactivity in tabhost. I am trying your code their. it doesn't show popup, it doesn't throw any error either. did you try your code in tabhost?
Please see my code:
public class FinderHome extends MapActivity {
Context context=null;
View v=null;
EditText txtSearchPeople=null;
MapView mapFindingResults=null;
List<Overlay> mapOverlays;
Drawable drawable;
MyItemizedOverlay itemizedOverlay;
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.v("FinderHome", "Activity State: onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.finder_home);
txtSearchPeople=(EditText) findViewById(R.id.txtSearchPeople);
mapFindingResults = (MapView) findViewById(R.id.mapFindingResults);
//mapFindingResults.getController().setZoom(17);
mapFindingResults.setBuiltInZoomControls(true);
EditTextKeyListener keyListener=new EditTextKeyListener();
txtSearchPeople.setOnKeyListener(keyListener);
mapOverlays = mapFindingResults.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.androidmarker);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight());
itemizedOverlay = new MyItemizedOverlay(drawable,this);
LoadResults();
}
private void LoadResults(){
//my position
GeoPoint point = new GeoPoint(19240000,-99120000);
OverlayItem overlayitem = new OverlayItem(point, "Me", "Me");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
//get list from webservice
//loop through results and add people
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
//subclass to handle KeyListener event of EditText
private class EditTextKeyListener implements OnKeyListener{
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode ==
KeyEvent.KEYCODE_ENTER))
{
EditText myEditText=(EditText) v;
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
}
else if ((event.getAction() == KeyEvent.ACTION_UP) && (keyCode ==
KeyEvent.KEYCODE_BACK))
{
finish();
}
return true;
}
}
public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context context=null;
private PopupPanel panel=new PopupPanel(R.layout.map_popup);
public MyItemizedOverlay(Drawable defaultMarker,Context context){
super(boundCenterBottom(defaultMarker));
this.context=context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
@Override
protected boolean onTap(int i) {
//Toast.makeText(context, mOverlays.get(i).getSnippet(), Toast.LENGTH_SHORT).show();
OverlayItem item=getItem(i);
GeoPoint geo=item.getPoint();
Point pt=mapFindingResults.getProjection().toPixels(geo, null);
View view=panel.getView();
((TextView)view.findViewById(R.id.tvBuddyName))
.setText(item.getSnippet());
panel.show(pt.y*2>mapFindingResults.getHeight());
return(true);
}
@Override
public int size() {
return mOverlays.size();
}
}
class PopupPanel {
View popup;
boolean isVisible=false;
PopupPanel(int layout) {
ViewGroup parent=(ViewGroup)mapFindingResults.getParent();
popup=getLayoutInflater().inflate(layout, parent, false);
popup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
hide();
}
});
}
View getView() {
return(popup);
}
void show(boolean alignTop) {
RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
if (alignTop) {
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.setMargins(0, 20, 0, 0);
}
else {
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
lp.setMargins(0, 0, 0, 60);
}
hide();
((ViewGroup)mapFindingResults.getParent()).addView(popup, lp);
isVisible=true;
}
void hide() {
if (isVisible) {
isVisible=false;
((ViewGroup)popup.getParent()).removeView(popup);
}
}
}
}
Please let me know, if I am doing something wrong. thanks in advance.
Regards,
Azam.