Issue
I hope you feel good.
So to my question, i am inflating a layout menu like you see at the bottom, but now I'll get an error while inflating the layout.
Here's the complete code of my layout and of the on ItemLongClick method. In addition I wanna create a long click on a Listitem and then let a popup came on the screen with different words like edit delete whatever.
Is there anything wrong with my layout (ConstraintLayout)?
listView = (ListView) findViewById(R.id.listView);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
PopupMenu p = new PopupMenu(ViewListContents.this, v);
MenuInflater inflater = p.getMenuInflater();
inflater.inflate(R.layout.popup_layout, p.getMenu());
p.show();
return true;
}
});
My popup_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout="@layout/include"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item
android:id="@+id/order_takeout"
android:layout_width="145dp"
android:layout_height="126dp"
android:onClick="doTakeOut"
android:title="@string/delete"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<item
android:id="@+id/order_eat_in"
android:layout_width="114dp"
android:layout_height="110dp"
android:onClick="doEatIn"
android:title="@string/edit"
app:layout_constraintBottom_toTopOf="@+id/order_takeout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
I would like to thank you in advance for any feedback
Solution
You need a menu resource file, you can't have a layout resource file. Change the location of your XML file to the menu resource directory. If You don't have a menu resource directory, create it and place your XML file(pop_layout.xml) there.Also, you can't have a constraint layout in a menu resource file.ViewGroups are only for layout resource files,not for menu resource files.
Menu resporce files look like this :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/mail"
android:icon="@drawable/ic_mail"
android:title="@string/mail" />
<item android:id="@+id/upload"
android:icon="@drawable/ic_upload"
android:title="@string/upload"
android:showAsAction="ifRoom" />
<item android:id="@+id/share"
android:icon="@drawable/ic_share"
android:title="@string/share" />
Hope that helps.
Answered By - Rishabh Ritweek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.