0

I am creating an application which using custom view and i have designed the layout using a class that extends view.

Now i have a help icon on that view which have to popup on click.I have tried dialog window but i need a window without title and border.

I have checked some games and they are using what exactly i need. Anybody can suggest a better solution?

here is my sample code to get help button

public boolean onTouchEvent(MotionEvent me) {
        int action = me.getAction();
        if(action == MotionEvent.ACTION_DOWN ){
            x = me.getX();
            y = me.getY();
if (x >= helpButtonX && x < (helpButtonX +help.getWidth())&&
 y >= helpButtonY && y <     helpButtonY + help.getHeight() ) 
  {
           // code toshow popup
   }
  }
}
i leaf
  • 273
  • 7
  • 19

3 Answers3

1

Yes you can create a custom dialog with the layout designed by you.

For that simply create a dialog and set the layout by using setContentView() method.

For example:

 Dialog dialog = new Dialog(myActivity.this);
 dialog.setContentView(R.layout.myDialogLayout);
 dialog.setTitle("");
 dialog.setCancelable(true);
 dialog.show();
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
1

You can create a hidden View that is set using relativeLayout over the other elements in the layout.xml. when the user clicks the help button, the visibility is changed to visible and the View is shown. YOu can then set an onclick listener on the View that when they touch it, it will be hidden again.

ASceresini
  • 419
  • 3
  • 7
  • He doesnt want to use a dialog, this is another option that would be easy to code. – ASceresini Apr 30 '12 at 10:43
  • i don't have a xml file only a view created by code. Also i am confused about how the ontouchEvent will get the layout xml resource id – i leaf Apr 30 '12 at 10:50
  • why dont you create your layout in xml? and then setContentView on the Activity? that will allow you to easily create the GUI – ASceresini Apr 30 '12 at 10:52
  • i am using a custom view class as content view like public class TestPage extends View{} – i leaf Apr 30 '12 at 10:58
0

You can just use a PopupWindow with custom layout.

Add this code in your {//Code to show popup}

//Get a layout inflator
LayoutInflater li = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
//Initialize a popup window with custom xml view - R.layout.popup.xml
View popupView = li.inflate(R.layout.popup, null);
final PopupWindow pW = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

To dismiss it use pW.dismiss() wherever you want

Try this: http://android-er.blogspot.jp/2012/03/example-of-using-popupwindow.html

Kashif Siddiqui
  • 1,476
  • 14
  • 26