1

My problem is that i want to add fragment to my pop up window to display some information when a list is clicked. My list contains custom adapter. below is what i want to do :-

When list item is clicked, i get that model from adapterview and pass it to JobSearchModel. Now JobSearchModel contains the information that i want to display on JobDescription fragement. But i don't know how to add fragement to pop up window.

searchResult.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                JobSearchModel jobs = (JobSearchModel) adapterView.getItemAtPosition(i);

                JobDescription jobDescription = new JobDescription();

                Bundle args = new Bundle();
                args.putSerializable("jobs", jobs);

                jobDescription.setArguments(args);

                popupWindow.showAtLocation(jobDescription, Gravity.CENTER, 0, 0);
            }
        });

1 Answers1

-2

Copied From HERE

The following should work perfect in accordance with your specification. Call this method from inside onClick(View v) of OnClickListener assigned to the View:

public void showPopup(View anchorView) {

    View popupView = getLayoutInflater().inflate(R.layout.popup_layout, null);

    PopupWindow popupWindow = new PopupWindow(popupView, 
                           LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    // Example: If you have a TextView inside `popup_layout.xml`    
    TextView tv = (TextView) popupView.findViewById(R.id.tv);

    tv.setText(....);

    // Initialize more widgets from `popup_layout.xml`
    ....
    ....

    // If the PopupWindow should be focusable
    popupWindow.setFocusable(true);

    // If you need the PopupWindow to dismiss when when touched outside 
    popupWindow.setBackgroundDrawable(new ColorDrawable());

    int location[] = new int[2];

    // Get the View's(the one that was clicked in the Fragment) location
    anchorView.getLocationOnScreen(location);

    // Using location, the PopupWindow will be displayed right under anchorView
    popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY, 
                                     location[0], location[1] + anchorView.getHeight());

}

The comments should explain this well enough. anchorView is the v from onClick(View v).

Community
  • 1
  • 1
Danial Hussain
  • 2,488
  • 18
  • 38
  • This doesn't answer the question which is about adding a Fragment to a popup window. – 2Dee Jan 28 '15 at 10:38
  • 1
    From the help page : "Use your downvotes whenever you encounter an egregiously sloppy, no-effort-expended post, or an answer that is clearly and perhaps dangerously incorrect." – 2Dee Jan 28 '15 at 10:44