我有一个带有 ImageButton 的自定义标题栏,它会生成一个对话框,并且当从对话框中选择列表项并且标题栏和地图位于时,我希望能够在地图(在另一个类中)上显示位置(放置 itemizedOverlay)相同的上下文。我在某处读到我可以使用上下文调用另一个类的方法。我该怎么做?
public class MyTitleBar extends RelativeLayout{
private Context context;
public MyTitleBar(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
initViews();
}
// set up all the buttons & clicks
private void initViews() {
final ImageButton listImgBtn = (ImageButton) findViewById(R.id.more);
final CharSequence [] listItems = {"Elderly","Events"};
listImgBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(context instanceof UserHome)
{
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("List");
builder.setItems(listItems, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
// TODO Auto-generated method stub
if(item == 0)
{
//show location of elderly
//DisplayLocation()
}
else if(item == 1)
{
//show location of events
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
});