I am trying to set Cart Basket icon for Add To Cart functionality. While I run the app I got this error
Attempt to invoke virtual method 'android.view.View
android.widget.RelativeLayout.findViewById(int)' on a null object
reference
Here I am using AppCompatActivity.
My code is here:
MainActivity.java
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView();
mCounter = (TextView) badgeLayout.findViewById(R.id.counter);
return true;
}
menu.xml:
<item
android:id="#+id/badge"
android:actionLayout="#layout/badge_layout"
android:title="Badges"
app:showAsAction="always">
</item>
badge_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_gravity="right" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:clickable="true"
android:src="#drawable/ic_shopping_cart"/>
<TextView
android:id="#+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:padding="8dp"
android:text="12"
android:textSize="10sp"
android:textColor="#color/colorPrimary" />
</RelativeLayout>
Finally Got the cart icon.
Replace this
<item
android:id="#+id/badge"
android:actionLayout="#layout/badge_layout" //Check this LINE
android:title="Badges"
android:actionViewClass="android.widget.RelativeLayout"
app:showAsAction="always">
</item>
To
<item
android:id="#+id/badge"
app:actionLayout="#layout/badge_layout" //Check this LINE(Changes made here)
android:title="Badges"
android:actionViewClass="android.widget.RelativeLayout"
app:showAsAction="always">
</item>
Related
I am trying to implement a custom layout for my menu item and went through many solutions by I am getting Null pointer Exception whenever i try to fetch TextView inside the layout specified for actionLayout for my menuItem as the getActionView returns null.
home_menu:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/action_notifications"
android:title=""
app:showAsAction="always"
android:visible="true"
android:icon="#drawable/ic_notifications_black_24dp"
android:orderInCategory="3"
android:actionLayout="#layout/counter_action_bar_notification_icon"
/>
<!--android:icon="#drawable/ic_notifications_black_24dp"-->
<!--android:actionLayout="#layout/bage_layout"-->
</menu>
counter_action_bar_notification_icon
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center"
android:clickable="true"
style="#android:style/Widget.ActionButton">
<ImageView
android:id="#+id/hotlist_bell"
android:src="#drawable/ic_notifications_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="0dp"
android:contentDescription="bell"
/>
<TextView
android:id="#+id/hotlist_hot"
android:layout_width="wrap_content"
android:minWidth="17sp"
android:textSize="12sp"
android:textColor="#ffffffff"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#null"
android:layout_alignTop="#id/hotlist_bell"
android:layout_alignRight="#id/hotlist_bell"
android:layout_marginRight="0dp"
android:layout_marginTop="3dp"
android:paddingBottom="1dp"
android:paddingRight="4dp"
android:paddingLeft="4dp"
android:background="#drawable/bage_circle"/>
</RelativeLayout>
MainActivity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.home_menu, menu);
item = menu.findItem(R.id.action_notifications);
if(loginStatus==false){
item.setVisible(false);
return false;
}
if(user!=null && !user.getUserType().equals("3")){
item.setVisible(false);
return false;
}
final View menu_hotlist = MenuItemCompat.getActionView(item);
TextView ui_hot =(TextView) menu_hotlist.findViewById(R.id.hotlist_hot);
ui_hot.setText(Integer.toString(13));
return true;
}
Try this
item.setActionView(R.layout.counter_action_bar_notification_icon);
final View menu_hotlist = MenuItemCompat.getActionView(item);
TextView ui_hot =(TextView) menu_hotlist.findViewById(R.id.hotlist_hot);
ui_hot.setText(Integer.toString(13));
Use
app:actionLayout
instead of
android:actionLayout
in your layout file and dont forget to define app
xmlns:app="http://schemas.android.com/apk/res-auto"
It is because getActionView() return the view injected in app:actionViewClass item attribute.
For example
<item android:id="#+id/action_search"
android:title="#string/option_search"
android:icon="#drawable/ic_action_search"
app:showAsAction="collapseActionView|ifRoom"
app:actionViewClass="YourCustomView"/>
Here getActionView() will return a YourCustomView reference. You have to inject your view object with app:actionViewClass instead of android:actionLayout. Then you have to create your Java class YourCustomView extends RelativeLayout which inflate R.layout.counter_action_bar_notification_icon
I am Working on Android Menu Items. I can able to add Badges with the Items that are displayed in the Action Bar .But i want to show the same Badges with the Overflow Menu Items. Is there any solutions to Add Badges to Menu Items in overflow menu Like the Sample Image and
Any help would greatly appreciated..!!!
can you please try following.
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/badge"
android:actionLayout="#layout/badge_layout"
android:title="Badges"
android:showAsAction="always">
</item>
</menu>
Here badge_layout is you menu item layout with the badge.
and following are code to implement in activity.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.badge).getActionView();
mCounter = (TextView) badgeLayout.findViewById(R.id.counter);
return true;
}
Finally i did it with the Help ofCustom PopUp Window + BadgeView
Here what i have Done.
Created Custom Layout For PopUp Window - custom_popup.xml
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/icon_menu_facebook"
android:text="Icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notifications" />
<TextView
android:id="#+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/icon_menu_facebook"
android:text="Icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notifications" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/icon_menu_facebook"
android:text="Icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notifications" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
2.Added Menu Item with Custom Icon (Overflow Menu Icon)- options_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/ViewSource"
android:icon="#drawable/ic_action_viewsource"
android:title="ViewSource"
app:showAsAction="ifRoom" />
<item
android:id="#+id/about"
android:icon="#drawable/ic_action_about"
android:title="About"
app:showAsAction="ifRoom">
<!-- "file" submenu -->
<menu>
<item
android:id="#+id/github"
android:icon="#drawable/icon_menu_github"
android:title="Github" />
<item
android:id="#+id/linkedin"
android:icon="#drawable/icon_menu_linkedin"
android:title="LinkedIn" />
<item
android:id="#+id/twitter"
android:icon="#drawable/icon_menu_twitter"
android:title="Twitter" />
<item
android:id="#+id/facebook"
android:icon="#drawable/icon_menu_facebook"
android:title="Facebook" />
</menu>
</item>
<item
android:id="#+id/notifications"
android:icon="#drawable/ic_action_name"
android:title="More"
app:showAsAction="always"></item>
</menu>
In MainActivity.java Added the following Code with in onOptionsItemSelected(MenuItem item)
case R.id.notifications:
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View CustomPopUp = layoutInflater.inflate(R.layout.custom_popup, null);
popupWindow = new PopupWindow(CustomPopUp, ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT);
if (Build.VERSION.SDK_INT >= 21) {
popupWindow.setElevation(5.0f);
}
ViewGroup actionBar = getActionBar(getWindow().getDecorView());
TextView tv_badge = (TextView) CustomPopUp.findViewById(R.id.badge);
BadgeView badge = new BadgeView(activity);
badge.setTargetView(tv_badge);
badge.setBadgeCount(45);
popupWindow.showAtLocation(actionBar, Gravity.TOP | Gravity.RIGHT, 0, -70);
popupWindow.setAnimationStyle(R.style.Animation);
linearlatout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
return true;
default:
return super.onOptionsItemSelected(item);
Thats all..!!! Happy Coding...!!!
I'm trying to inflate an options menu on a button click.
I managed to inflate it using openOptionsMenu(); in button's onClick event(as we are using a layout with custom fields like ImageView, Textbox on the action bar).
But the menu is inflated on the bottom. Right now my menu is inflated like below image:
I want it to be opened vertically(some thing like below).
How can I do it?
Below are my code samples:
Main Activity:
private Button optionsMenu;
optionsMenu = (Button)findViewById(R.id.optionsMenu);
In onCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
optionsMenu.setOnClickListener(menuInflate);
private OnClickListener menuInflate = new OnClickListener() {
#Override
public void onClick(View v) {
openOptionsMenu();
}
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Uri uri;
Intent i;
switch (item.getItemId()) {
case R.id.option1:
uri = Uri.parse("http://www.yahoo.com");
i = new Intent(Intent.ACTION_VIEW, uri);
startActivity(i);
return true;
case R.id.option2:
uri = Uri.parse("tel:92345678");
i = new Intent(Intent.ACTION_CALL, uri);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
options_menu.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/option1" android:title="About"
android:orderInCategory="101" android:showAsAction="withText" />
<item android:id="#+id/option2" android:title="Help"
android:orderInCategory="102" android:showAsAction="withText" />
</menu>
menu_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/content_bg_color">
<RelativeLayout
android:id="#+id/menu_sub_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<com.abc.ThirdParty.SmartImageView
android:id="#+id/user_profile_image"
android:layout_width="54dip"
android:layout_height="54dip"
android:scaleType="fitXY"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/portrait"/>
<TextView
android:id="#+id/username_text_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/user_profile_image"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:gravity="center"
android:textSize="22sp"
android:fontFamily="sans-serif-light"
android:textStyle="bold"
android:textColor="#android:color/white"/>
<Button
android:id="#+id/optionsmenu_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:gravity="center"
android:background="#drawable/ic_options_menu"/>
</RelativeLayout>
</RelativeLayout>
To show the menu items on click, set their showAsAction attribute to never as described in the docs :
never : Never place this item in the app bar. Instead, list the item in the app bar's overflow menu.
So set this for the items that you want in the overflow menu :
android:showAsAction="never"
UPDATE
Also, remove the optionsMenu image (the one with three dots) that you've put on the Toolbar manually. Android will put that icon itself if there are menu items with showAsAction attribute set to never or there isn't enough space in the Toolbar to show the items.
and remove these methods from the onClickListener of your image and put them inside your Activity class :
#Override
public boolean onCreateOptionsMenu(Menu menu)
#Override
public boolean onOptionsItemSelected(MenuItem item)
UPDATE #2
If you want a custom Toolbar with overflow menu button, there's no need to put a Button(with 3 dots icon) for that. If you want to customize the Toolbar put your whole layout code inside Toolbar in the xml and set that as the Activity's Toolbar inside onCreate like this :
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/content_bg_color">
<RelativeLayout
android:id="#+id/menu_sub_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_bg"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<com.abc.ThirdParty.SmartImageView
android:id="#+id/user_profile_image"
android:layout_width="54dip"
android:layout_height="54dip"
android:scaleType="fitXY"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/portrait"/>
<TextView
android:id="#+id/username_text_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/user_profile_image"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:gravity="center"
android:textSize="22sp"
android:fontFamily="sans-serif-light"
android:textStyle="bold"
android:textColor="#android:color/white"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Then set the toolbar in the onCreate like this :
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
and don't worry about the overflow menu button, it'll be added automatically in the cases discussed above.
Here's the output of this code :
Change your options_menu.xml like this
<item
android:id="#+id/option1"
android:orderInCategory="100"
android:title="About"
app:showAsAction="never" />
<item
android:id="#+id/option2"
android:orderInCategory="100"
android:title="Help"
app:showAsAction="never" />
And in your Activity..
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.option1) {
//perform with Option1 here
} else if (item.getItemId() == R.id.option2) {
//perform with Option2 here
}
return super.onOptionsItemSelected(item);
}
it will automatically put the button that you want no need to put manually!
I have actionbar_badge_layout.xml file under layout as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_gravity="right" >
<!-- Menu Item Image -->
<ImageView
android:layout_width="48dp"
android:layout_height="fill_parent"
android:clickable="true"
android:src="#mipmap/icon_back" />
<!-- Badge Count -->
<TextView
android:id="#+id/actionbar_notifcation_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="99"
android:textColor="#color/primary_dark_material_light" />
Inside res/menu_comment xml I have :
<item
android:id="#+id/action_add"
android:icon="#mipmap/ic_menu_add"
android:actionLayout="#layout/actionbar_badge_layout"
android:title="Add"
app:showAsAction="always">
</item>
Then inside my activity I have onCreateOptionsMenu() as:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_comment, menu);
RelativeLayout badgeLayout = (RelativeLayout) menu.findItem(R.id.action_add).getActionView();
TextView t = (TextView)badgeLayout.findViewById(R.id.actionbar_notifcation_textview); //here I am getting null pointer exception
t.setText("12");
return true;
}
But I am getting NullPointer exception. Logcat gives me output as:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.RelativeLayout.findViewById(int)' on a null object reference
at com.mypackage.activities.ShowCommentsActivity.onCreateOptionsMenu(ShowCommentsActivity.java:77)
at android.app.Activity.onCreatePanelMenu(Activity.java:2820)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:275)
at android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:276)
at android.support.v7.app.ActionBarActivityDelegate$1.onCreatePanelMenu(ActionBarActivityDelegate.java:79)
at android.support.v7.widget.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:49)
at android.support.v7.internal.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:459)
at android.support.v7.internal.app.ToolbarActionBar$1.run(ToolbarActionBar.java:69)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
what is wrong in this code. Any suggestion will be appreciated. Thanks in advace
Where are you closing the RelativeLayout?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="48dp"
android:layout_height="fill_parent"
android:layout_gravity="right" >
<!-- Menu Item Image -->
<ImageView
android:layout_width="48dp"
android:layout_height="fill_parent"
android:clickable="true"
android:src="#mipmap/icon_back" />
<!-- Badge Count -->
<TextView
android:id="#+id/actionbar_notifcation_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="99"
android:textColor="#color/primary_dark_material_light" />
Add </RelativeLayout> at the end of the XML file.
Also, try changing your
<item
android:id="#+id/action_add"
android:icon="#mipmap/ic_menu_add"
android:actionLayout="#layout/actionbar_badge_layout"
android:title="Add"
app:showAsAction="always">
</item>
to,
<item
android:id="#+id/action_add"
android:icon="#mipmap/ic_menu_add"
app:actionLayout="#layout/actionbar_badge_layout"
android:title="Add"
app:showAsAction="always">
</item>
Try to call below function from onCreate() :
private void setActiobarTitle(String title)
{
View v = getActionbar().getCustomView();
TextView t = (TextView) v.findViewById(R.id.actionbar_notifcation_textview);
t.setText("12");
}
Note : Also set actionBar.setDisplayShowCustomEnabled(true); to enable custom layout in action bar.
Please go through the below image
http://i.imgur.com/3WqhVCj.jpg
I dont have any action bar and I made my custom header using below layouts which is shown in Figure-2
[Linearlayout]
[Relativelayout]
[linearlayout]
Back Button
App Icon
My APP text
Overflow Icon
[/Linearlayout]
[/Relativelayout]
[/linearlayout ]
now i need the dropdown like shown in Figure-1 on clicking overflow icon which is shown in red box on top right in Figure-2
how could i do this? I have tried spinner it giving me popup but i need just dropdown shown in Figure-1.
plz suggest me
First of all create a function or method in your java class file:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater menuINF= getMenuInflater();
menuINF.inflate(R.menu.menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.***:
break;
}
And add menu content by adding menu folder in res folder and create menu.xml in that folder (res->menu->menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add" android:title="Add" android:icon="#drawable/icon"/>
<item android:id="#+id/menu_DashBoard" android:title="DashBoard" />
<item android:id="#+id/menu_Master_Entry" android:title="Master Entry" />
<item android:id="#+id/menu_Product_Section" android:title="Product Section" />
<item android:id="#+id/menu_Retailers_Orders" android:title="Retailers Orders" />
</menu>
This may help you Its works for me.
Use dialog (Example)
And to place dialog to correct height and width use
WindowManager.LayoutParams wmlp = dialog.getWindow().getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.CENTER_RIGHT;
BitmapDrawable bd=(BitmapDrawable) this.getResources().getDrawable(R.drawable.urdrawable);//urdrawable is your top bar image
int height=bd.getBitmap().getHeight();
//int width=bd.getBitmap().getWidth();
//wmlp.x = width; //x position
wmlp.y = height; //y position
Try this..
For list_popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#44444d"
>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text1"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text2"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
<TextView
android:layout_height="50dp"
android:layout_width="match_parent"
android:text="text3"
android:textSize="18dp"
android:textColor="#FFFFFF"
android:gravity="center"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#999999"
/>
</LinearLayout>
java
LayoutInflater layoutInflater= (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View popupView = layoutInflater.inflate(R.layout.list_popup, null);
final PopupWindow popupWindow = new PopupWindow(popupView,200,LayoutParams.WRAP_CONTENT);
onClick.
show_options.setOnClickListener(new Button.OnClickListener(){
public void onClick(View arg0) {
if(popupWindow.isShowing())
popupWindow.dismiss();
else
popupWindow.showAsDropDown(show_options, 50, 0);
}
});
show_options is your overflow icon image name
Here is some example
http://rajeshandroiddeveloper.blogspot.in/2013/07/android-popupwindow-example-in-listview.html
http://www.androidhub4you.com/2012/07/how-to-create-popup-window-in-android.html