0

Background

I have an app that shows a list of apps, and has an actionBar. one of the actionBar items has a sub menu that show the various ways to sort the list that is shown on the screen.

The problem

I'm trying to make the app being translated to Greek, and it turns out that some textual UI elements do not have multi-line inside them, which makes the text become truncated.

Context menu is one of them, so I've made my own implementation of it using an AlertDialog.

However, I see the same problem on the actionBar sub menu, and I think the same problem appears when using the PopupMenu class :

(look at the third item in the sub menu)

enter image description here

The question

Is there an easy way to overcome this issue, or should I make my own implementation of it, as I've done for the context menu?

Is there also a way to overcome this issue for PopupMenu?

Would adding a style for popupMenu (as shown here) help?

How do I make the textViews that are used on those UI components have multi-line in them?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • You can change the style of this menu so you can change the size of the text with `textSize` option. So, I think that if you reduce the text size it won't truncate. – luiscosta Jul 18 '14 at 13:45
  • @Akagami I don't want to reduce the size of the text. I just want to make it multi-line as needed. – android developer Jul 18 '14 at 13:46
  • @android_developer I think you have to create a custom layout for that. See this link: http://stackoverflow.com/questions/14868774/android-action-bar-custom-dropdown-view-on-item-click – luiscosta Jul 18 '14 at 13:50
  • @Akagami Maybe I could use the PopupMenu class, and duplicate everything from the actionBar sub menu, yet use multi-line instead? is it possible? I can't find out how to achieve it though... Maybe I should use PopupWindow instead? – android developer Jul 18 '14 at 22:48
  • @android_developer I would go for the custom layout but I posted an answer for a PopupWindow. Check it out if you decide to use one! – luiscosta Jul 21 '14 at 08:56

1 Answers1

0

Creating a PopupWindow:

private ArrayAdapter<String> adapterTypeSelection;
private void popupWindow(View v, Point p) {

    // int popupwindowWidth =
    // UnitConverterClass.convertDpToPx(180,getActivity());
    int popupwindowHeight = LinearLayout.LayoutParams.WRAP_CONTENT;

    LayoutInflater layoutInflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(
            R.layout.dashboard_profile_popup_window, null);

    // Creating the PopupWindow
    final PopupWindow pwindow = new PopupWindow(getActivity());
    pwindow.setContentView(layout);
    // pwindow.showAsDropDown(v);
    // pwindow.setWidth(popupwindowWidth);
    pwindow.setHeight(popupwindowHeight);
    pwindow.setFocusable(true);

    String[] types = {"hello", "hi"};

    adapterTypeSelection = new ArrayAdapter<String>(getActivity(),
            R.layout.<your layout for the popupwindow>,
            R.id.textView, types);

    ListView listview = (ListView) pwindow.getContentView().findViewById(
            R.id.listview_popwindow);

    listview.setAdapter(adapterTypeSelection);

    listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            TextView temp = (TextView) parent.getChildAt(position)
                    .findViewById(R.id.textView);

            if (temp.getText()
                    .toString()
                    .equals("hello"))) {
                //hello
            } else {
                //hi
            }

            pwindow.dismiss();
        }
    });

    pwindow.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss() {
            //TODO dismiss settings
        }

    });

    pwindow.setWidth(<width>);
    pwindow.setBackgroundDrawable(<resource for background>);

    // int OFFSET_X = UnitConverterClass.convertDpToPx(180, getActivity());
    // int OFFSET_Y = UnitConverterClass.convertDpToPx(30, getActivity());
    // pwindow.showAtLocation(layout, Gravity.NO_GRAVITY, 
    //                                p.x + OFFSET_X, p.y + OFFSET_Y);
    pwindow.showAtLocation(layout, Gravity.NO_GRAVITY, p.x, p.y);
}

Then you create a OnClickListener for the button like this:

actionBarButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            int[] location = new int[2];
            v.getLocationOnScreen(location);

            // Initialize the Point with x, and y positions
            Point point = new Point();
            point.x = location[0];
            point.y = location[1];

            popupWindow(v, point);

        }

    }
);

Hope this helps if you really want to use a PopupWindow but I would still go for the custom layout on the menu.

luiscosta
  • 855
  • 1
  • 10
  • 16
  • ummm.... the content was correct, but the name wasn't. I've now deleted the post. here's the content: Interesting. Sadly I can't do it right now, as I have an army-draft (I'm from Israel), so I hope to remember to get back to this some time in the future. thank you. – android developer Jul 28 '14 at 16:09