I've a problem to create a popup menu on Android. Pratically, I want to load dynamically the popup but when I execute the app, the menu is out of screen and doesn't anchored on button...why?
This is a screen to understand:
This is a summary code that I use to create my popupmenu:
public class MainActivity extends FragmentActivity
{
PopupMenu select_job;
@Override
protected void onCreate(Bundle savedInstanceState)
{
//...
View view = inflater.inflate(R.layout.my_custom_layout ,null);
select_job = new PopupMenu(this, view);
select_job.getMenu().add("ProvaLavoro");
}
public boolean onOptionsItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case R.id.popupmenu:
select_job.show();
break;
}
}
}
This is my_custom_layout.xml to inflate whitin:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txtNameJobND"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:textColor="#111"
android:textStyle="bold"/>
</RelativeLayout>
What am I doing wrong?
Thanks!!