java.lang.NullPointerException while adding text on actionbar icon - android

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.

Related

MenuItemCompat.getActionView Returns Null

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

How to Display Badges with Menu Items that are displayed in the overflow menu

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...!!!

ToolBar MenuItem error

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>

How to Make LinearLayout Clickable

I have a linearlayout like this
<LinearLayout
android:id="#+id/optionlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/divider"
android:orientation="vertical" >
</LinearLayout>
I want to add another xml view into this layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/option"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!--
<View
android:layout_width="match_parent"
android:layout_height="0.5dip"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#2fd275"
/>
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="10dp" >
<ImageView
android:id="#+id/option_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/logout" />
<TextView
android:id="#+id/option_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:visibility="gone" />
<TextView
android:id="#+id/option_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
android:text="Signout"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#616161" />
</LinearLayout>
<View
android:id="#+id/divider"
android:layout_width="match_parent"
android:layout_height="0.5dip"
android:background="#d3d3d3" />
</LinearLayout>
via the code
for (int i = 0; i < opt.length; i++) {
View view = inflater.inflate(R.layout.option_item, optionlist,
false);
view.setBackgroundResource(R.drawable.optionlist);
view.setTag(opt_image[i]);
view.setClickable(true);
view.setFocusable(true);
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// ADD your action here
int res = (Integer) v.getTag();
switch (res) {
case R.drawable.logout:
signout();
break;
}
}
});
final TextView tv = (TextView) view.findViewById(R.id.option_name);
final ImageView iv = (ImageView) view
.findViewById(R.id.option_image);
tv.setText(opt[i]);
iv.setImageResource(opt_image[i]);
optionlist.addView(view);
}
Now on click of the layout i want to load this xml file as below...but i am not able to get the backgroud loaded on the click event. Please give suggestion what am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/holo_green_dark" android:state_focused="true"/>
<item android:drawable="#color/holo_green_dark" android:state_enabled="false" android:state_pressed="true"/>
<item android:drawable="#color/white"/>
</selector>
First get id of LinearLayout from xml and then perform onClickListener on it instead of whole View
View view = inflater.inflate(R.layout.option_item, optionlist, false);
LinearLayout layout = view.findViewByIt(R.id.optionlist);
layout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// ADD your action here
int res=(Integer) v.getTag();
switch(res)
{
case R.drawable.logout: signout();
break;
}
}
});
try this.. hope it works..
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#ff0000" />//ur onclick desired color
<item android:state_focused="false"
android:drawable="#android:color/transparent" />focused color
</selector>
just create new xml and add this code in drawable and set ur linear layoyut backgrout as its name like android:background="#drawable/createdxmlname"
<LinearLayout
android:id="#+id/optionlist"
android:layout_below="#id/divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/createdxmlname"
android:clickable="true">
android:clickable="false"
<LinearLayout
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:clickable="false"
android:layout_width="40dp"
android:layout_height="40dp"
android:text="Cinema"
android:textSize="13sp"
android:layout_marginRight="10dp" />
<Button
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="Check in"
android:textSize="13sp" />
</LinearLayout>
Create in drawable an pressed_layout.xml with the following content
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="#drawable/button_focused" /> <!-- focused -->
<item android:drawable="#drawable/button_normal" /> <!-- default -->
</selector>
And in your layout add it as background resource:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/pressed_layout"
android:clickable="true">
</LinearLayout>
layout.setclickble="true" in XML file and
layout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
}
});
We can also use onClick in XML of layout,and use that method in java file,like if onClick="next",then in java file we have to use the method .
public void next()
{
// do something
}

Dropdown on image click in android

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

Categories

Resources