Reputation: 449
I am working on app where I have to show Popup within my main Activity, in Pop up I have one Button on which I need to perform some operation.
Please see my code bellow. The code does not give any error but the button click of Popup window is not working.
imgOpenPopup = (ImageView) findViewById(R.id.places);
imgOpenPopup.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflater = (LayoutInflater) ConvergeActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = inflater.inflate(R.layout.placepopup,(ViewGroup)findViewById(R.layout.maincam));
popupWindow = new PopupWindow(inflater.inflate(
R.layout.placepopup, null, false), 200, 265, true);
popupWindow.showAtLocation(findViewById(R.id.places),
Gravity.CENTER, 0, 0);
objbtnpopupOk=(Button)popupView.findViewById(R.id.btnokpopup);
objbtnpopupOk.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(getApplicationContext(), " hi thrtrt " ,Toast.LENGTH_LONG).show();
}
});
}
});
Upvotes: 1
Views: 26153
Reputation: 2409
I have done it this way:
popupWindow.getContentView().setOnClickListener(new OnClickListener()...);
I hope it helps.
Upvotes: 1
Reputation: 449
I really dont know what went wrong but this solution worked out for me.
cheers.
Upvotes: 3
Reputation: 2425
Try this:
View popupView = inflater.inflate(R.layout.placepopup,(ViewGroup)findViewById(R.layout.maincam));
popupWindow = new PopupWindow(popupView, 200, 265, true);
instead this:
View popupView = inflater.inflate(R.layout.placepopup,(ViewGroup)findViewById(R.layout.maincam));
popupWindow = new PopupWindow(inflater.inflate(R.layout.placepopup, null, false), 200, 265, true);
Upvotes: 3
Reputation: 418
Do the popup in another activity :
Add this theme to the styles file and then set it to the activity that you want to pop up in the manifest file. I am sure that the button will work in another activity.
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Upvotes: 0
Reputation: 2534
Why don't you try to use AlertDialog
. That will help you.Read this Alert Dialog
Upvotes: 0
Reputation: 640
try to lift the creation of a popup window out of the OnClickListener, and in onClick just call the method to show the popup window. It has few optimization improvements and it can solve your issue.
Upvotes: 0