I am writing an Android app in which I have a Map activity where I have a few buttons and what not. I have a map.xml for the layout for this. In this map I set annotations and the “annotation balloons” for this by using this library I found online (I forgot the name but I’ll find it if you guys want to know). This part works fine. The problem occurs when I put a button in another xml (put a button in the “annotation balloon” overlay xml) that is used for annotation balloons. I would like to detect the click in my map activity but it seems that it never goes in the onClick method. This is what I am doing in my activity to set the listener:
LinearLayout layout = new LinearLayout(getApplicationContext());
LayoutInflater inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.balloon_overlay, layout);
Button quickPathfindButton = (Button) v.findViewById(R.id.map_quickpathfind_button);
quickPathfindButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
quickPathfind();
}
});
It seems that it never goes in the onClick method. Do you guys know why this could be the case? Let me know if you don’t understand my question. It is very hard to word it.
Thanks!
You are attaching the listener to the button in a view hierarchy that isn’t part of the activity. Try setting the onClick attribute of the button in the xml and writing the method in your activity. It should then automagically call the method when clicked.