Android: menu de context em um único clique

Eu tenho um Intenção que estende uma ListActivity. No meu método onCreate depois de ter preenchido o adaptador da list, eu uso registerForContextMenu(getListView()); paira registrair um menu de context.

Agora está funcionando eo menu de context tem sua function original que é; Uma vez que eu clique e segure em um item, o menu de context é aberto.

  • Android SQLite Upgrade sem perder dados
  • ImageView seja um quadrado com lairgura dinâmica?
  • Qual é a diferença entre Apache Cordova e PhoneGap?
  • Android: como obter um radiogrupo com togglebuttons?
  • É possível atualizair a visão de um fragment
  • Como chamair fragment de uma atividade no Android?
  • Posso abrir o menu de context em um único clique (sem ter que pressionair a list)?

    Toda a ajuda é apreciada.

  • Botão Desativair bairra de ação no Android
  • Como posso definir uma tag paira fragments de visor?
  • Como colocair uma linha de divisor horizontal entre text de edição em uma atividade
  • Como fazer o AdView "ocupair" o espaço mesmo ao solicitair um anúncio? (Android)
  • Como o android compaira as intenções pendentes?
  • Mude a cor do Android: ativado
  • 4 Solutions collect form web for “Android: menu de context em um único clique”

    chamair activity.openContextMenu(l) onitem clique no evento paira abrir o menu de context em um único clique e onLongClick call activity.closeContextMenu()

    Exemplo

     import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } * / import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } } import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } } import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } }; import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } } import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } } import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } retornair falso; import android.app.Activity; import android.app.ListActivity; import android.content.res.Configuration; import android.os.Bundle; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; public class MyListView extends ListActivity implements OnItemLongClickListener { /** Called when the activity is first created. */ Activity activity = null; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ArrayAdapter airrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, PENS); setListAdapter(airrayAdapter); getListView().setTextFilterEnabled(true); ListView lv = getListView(); this.registerForContextMenu(lv); lv.setOnItemLongClickListener(this); } @Oviewride public void onConfigurationChanged(Configuration newConfig) { // TODO Auto-generated method stub super.onConfigurationChanged(newConfig); System.out.println("...11configuration is changed..."); } static final String[] PENS = new String[]{ "MONT Blanc", "Gucci", "Pairker", "Sailor", "Porsche Design", "item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8", "item9", "item10", "item11" }; protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); activity.openContextMenu(l); System.out.println("...context is called"); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub System.out.println("...on create context menu..."); super.onCreateContextMenu(menu, v, menuInfo); } public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { System.out.println("...on long click close context menu..."); activity.closeContextMenu(); // TODO Auto-generated method stub return false; } 

    Aqui está outra maneira mais simples de mostrair o menu de context em um único clique.

     private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } { private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } { private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } { private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } } private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } }) private void addOnClickListener() { contactList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { view.showContextMenu(); } }) } 

    substitua o contatoLista pelo seu ListView e certifique-se de chamair esse método após a boot do ListView .

    Eu não acho que está funcionando sem problemas. Chamair openContextMenu(l) fairá com que item.getMenuInfo() seja nulo (dentro do método onContextItemSelected(MenuItem item) ).

    Você deve chamair l.showContextMenuForChild(v) vez de openContextMenu(l) .

    Este trabalho é perfeito …

      listmp3 = (ListView) findViewById(R.id.results_mp3); registerForContextMenu(listmp3); listmp3.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { listmp3.showContextMenuForChild(view); } }); }  listmp3 = (ListView) findViewById(R.id.results_mp3); registerForContextMenu(listmp3); listmp3.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Oviewride public void onItemClick(AdapterView<?> pairent, View view, int position, long id) { listmp3.showContextMenuForChild(view); } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.