title: how to create menu in android on click of list view?
body: <p>I am trying to create menu in android .Actually I want to show delete Icon when I long press in my list item .
  I tried like this .I create one <strong>my_menu.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;item android:id="@+id/id_delete"
  
      android:title="Delete"
      android:icon="@drawable/delete"&gt;&lt;/item&gt;
  &lt;/menu&gt;
  </code></pre>
  
  <p>Then I create list view .My list view is display on view but it is not showing delete icon when i press long on row .Mean I want to show menu option when I press long on row .I am able to display list..but menu is not display.</p>
  
  <p>here is my java code .</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      ListView listView;
      ArrayList arrayList = new ArrayList();
      ArrayList selectionList = new ArrayList();
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          listView = (ListView) findViewById(R.id.list_view);
  
          Log.d("==", loadJSONFromAsset());
          try {
              JSONArray js = new JSONArray(loadJSONFromAsset());
              for (int i = 0; i &lt; js.length(); i++) {
                  JSONObject obj = js.getJSONObject(i);
                  arrayList.add(obj.getString("name"));
              }
              //adp=new CustomAddapter(getApplicationContext(),R.layout.list_view);
  
  
              ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, arrayList);
              listView.setAdapter(adapter);
              listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
              listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
                  @Override
                  public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                      if (checked) {
                          selectionList.add(arrayList.get(position));
                          //  arrayList.add(arr.)
                      }
  
                  }
  
                  @Override
                  public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                      MenuInflater menuInflater = getMenuInflater();
                      menuInflater.inflate(R.menu.my_menu, menu);
                      return true;
                  }
  
                  @Override
                  public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                      return false;
                  }
  
                  @Override
                  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                      return false;
                  }
  
                  @Override
                  public void onDestroyActionMode(ActionMode mode) {
  
                  }
              });
  
  
          } catch (JSONException e) {
              e.printStackTrace();
          }
      }
  
      public String loadJSONFromAsset() {
          String json = null;
          try {
  
              InputStream is = getAssets().open("data.json");
  
              int size = is.available();
  
              byte[] buffer = new byte[size];
  
              is.read(buffer);
  
              is.close();
  
              json = new String(buffer, "UTF-8");
  
  
          } catch (IOException ex) {
              ex.printStackTrace();
              return null;
          }
          return json;
  
      }
  
  
  }
  </code></pre>