title: Custom ListView and context menu. How to get it?
body: <p>I have a two layouts files in my app. Also I have Activity extends ListActivity. Every item of this activity looks consider item.xml layout file. I am trying to get context menu when make long presss on item, but I don't see it.</p>
  
  <p>In my activity I trying to registerForContextMenu(getListView()) and override two methods</p>
  
  <pre><code>  @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Bundle bundle = this.getIntent().getExtras();
          registerForContextMenu(getListView());
          new PopulateAdapterTask().execute(ACTION_SELECT);   
       }
  
      @Override
          public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
              MenuInflater inflater = getMenuInflater();
              inflater.inflate(R.menu.context_menu, menu);
          }
  
  
          @Override
          public boolean onContextItemSelected(MenuItem item) {
              AdapterView.AdapterContextMenuInfo info;
              try {
                  info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
              } catch (ClassCastException e) {
                  return false;
              }
              long id = getListAdapter().getItemId(info.position);
              Log.d(TAG, "id = " + id);
              return true;
          }
  </code></pre>
  
  <p>Main.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android"
           android:id="@android:id/tabhost"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"&gt;
      &lt;LinearLayout
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="5dp"&gt;
          &lt;TabWidget
                  android:id="@android:id/tabs"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"/&gt;
          &lt;FrameLayout
                  android:id="@android:id/tabcontent"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:padding="5dp"&gt;
              &lt;ListView
                      android:id="@+id/list"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      /&gt;
  
          &lt;/FrameLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/TabHost&gt;
  </code></pre>
  
  <p>Item.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
       &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
          &gt;
      &lt;ImageView
              android:id="@+id/icon"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              /&gt;
      &lt;TextView
              android:id="@+id/info"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textSize="15sp"
              android:singleLine="true"
              android:ellipsize="marquee"
              android:scrollHorizontally = "true"
              android:maxWidth="200dp"
              /&gt;
  
  
      &lt;LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:gravity="right"
              &gt;
          &lt;ImageButton
                  android:id="@+id/button"
                  android:layout_width="wrap_content"
                  android:layout_height="fill_parent"
                  android:background="@null"
                  android:paddingRight="10dp"                
                  android:paddingLeft="10dp"
  
  
                  /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>All this doesn't work. Maybe the reason is in LinearLayout? I also find similar topic <a href="https://stackoverflow.com/questions/2890529/android-context-menu-doesnt-show-up-for-listview-with-members-defined-by-linear">Android: Context menu doesn&#39;t show up for ListView with members defined by LinearLayout?</a> but I have more complicated list item.</p>
  
  <p>How to get context menu in my case? </p>
  
  <p>Also in my activity I have inner class extends ArrayAdapter. In this class in getView method I can set OnCreateContextMenuListener on every View, after that context menu is appears, but I don't know how to handle items clicks. If I am trying to do this in method onContextItemSelected, item.getMenuInfo() object always is null and i can't to get some information from it.</p>
  
  <pre><code>private class ChannelAdapter extends ArrayAdapter&lt;Channel&gt; {
  
          private List&lt;Channel&gt; channels;
  
          public ChannelAdapter(Context context, int textViewResourceId, List&lt;Channel&gt; objects) {
              super(context, textViewResourceId, objects);
              this.channels = objects;
          }
  
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              View v = convertView;
              if (v == null) {
                  LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  v = vi.inflate(R.layout.station_item, null);
              }
  
  
                  v.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
                      public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                          MenuInflater inflater = getMenuInflater();
                          inflater.inflate(R.menu.context_menu, menu);
                      }
                  });
  </code></pre>
  
  <p>Thanks. Hope for your help.</p>