Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I got solution, my friend helped me! Hope this information will helpful to someone. This is complete class code with ArrayAdapter and complex list layout and context menu.</p> <pre><code> public class ComplexListActivity extends ListActivity { /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ComplexObjectAdapter(this, R.layout.item, getComplexObjects())); registerForContextMenu(getListView()); } private List getComplexObjects() { List&lt;ComplexObject&gt; list = new ArrayList&lt;ComplexObject&gt;(); list.add(new ComplexObject("1", "1", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("2", "2", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("3", "3", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("4", "4", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("5", "5", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("6", "6", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("7", "7", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("8", "8", getResources().getDrawable(R.drawable.icon))); list.add(new ComplexObject("9", "9", getResources().getDrawable(R.drawable.icon))); return list; } @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) { Log.e("", "bad menuInfo", e); return false; } long id = getListAdapter().getItemId(info.position); Log.d("", "id = " + id); Toast.makeText(this, "id = " + id, Toast.LENGTH_SHORT).show(); return true; } private class ComplexObjectAdapter extends ArrayAdapter&lt;ComplexObject&gt; implements View.OnCreateContextMenuListener { private List&lt;ComplexObject&gt; objects; public ComplexObjectAdapter(Context context, int textViewResourceId, List&lt;ComplexObject&gt; objects) { super(context, textViewResourceId, objects); this.objects = 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.item, null); } final ComplexObject o = objects.get(position); if (o != null) { TextView textlInfo = (TextView) v.findViewById(R.id.info); textlInfo.setText(o.getName()); ImageView channelIcon = (ImageView) v.findViewById(R.id.icon); channelIcon.setAdjustViewBounds(true); channelIcon.setMaxHeight(30); channelIcon.setMaxWidth(30); channelIcon.setImageDrawable(o.getLogo()); ImageButton button = (ImageButton) v.findViewById(R.id.button); button.setImageResource(R.drawable.icon); v.setOnCreateContextMenuListener(this); } return v; } public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) { // empty implementation } } } </code></pre> <p>let me know if someone will find better approach. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload