Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy the contextmenu isn't working?
    primarykey
    data
    text
    <p>I have a listview with a custon adapter. I have to put a context menu for it, but it's not working. And I put the <code>onItemLongClick</code> to the list and it's not working too. I don't know how to trigger the <code>contextmenu</code>. If I have to click on an item or long click on it. I do register a long click to get the id from the item.</p> <p><strong>EDIT</strong> I think i figure out whats the problem. I have a button on my item listview. I remove this button from the layout and the context menu worked fine. But I need this button. Why the button was causing problem in the context menu?</p> <p>This is the class:</p> <pre><code>public class HistoricoDespesasActivity extends Activity { Helper h; AlphaAnimation buttonClick; DespesasDAO dDAO; ListView lv; DespesaHistoricoAdapter adapter; int idDespesasSelecionada; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_historico_despesas); lv = (ListView)findViewById(R.id.lvHistoricoDespesas); TextView tvMarcaModelo = (TextView)findViewById(R.id.tvMarcaModeloCabecalho); TextView tvApelido = (TextView)findViewById(R.id.tvApelidoCabecalho); tvApelido.setVisibility(View.INVISIBLE); tvMarcaModelo.setVisibility(View.INVISIBLE); buttonClick = new AlphaAnimation(1, 0.5f); h = new Helper(this); h.mostraVeiculoAtivo(); adapter = new DespesaHistoricoAdapter(this); dDAO = new DespesasDAO(this); dDAO.open(); Cursor cursor = dDAO.consultarTodasDespesasByIdVeiculo(h.getId()); int id; String data; String tipoDespesa = null; double valor; int tipo = 0; if(cursor != null &amp;&amp; cursor.moveToFirst()){ do { id = cursor.getInt(cursor.getColumnIndex(DespesasDAO.COLUNA_ID)); data = cursor.getString(cursor.getColumnIndex(DespesasDAO.COLUNA_DESPESA_DATA)); tipo = cursor.getInt(cursor.getColumnIndex(DespesasDAO.COLUNA_ITEM_ID)); valor = cursor.getDouble(cursor.getColumnIndex(DespesasDAO.COLUNA_DESPESA_VALOR)); if(tipo == 1){ tipoDespesa = "Pedágio"; } else if(tipo == 2){ tipoDespesa = "Estacionamento"; } else if(tipo == 3){ tipoDespesa = "Lavagem"; } else if(tipo == 4){ tipoDespesa = "Diversos"; } adapter.addDespesa(id, tipoDespesa, data, valor); } while (cursor.moveToNext()); cursor.close(); dDAO.close(); lv.setAdapter(adapter); } lv.setLongClickable(true); lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { idDespesasSelecionada = (Integer) parent.getItemAtPosition(position); return true; } }); registerForContextMenu(lv); } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); menu.setHeaderTitle("Despesas"); menu.add(0, v.getId(), 0, "Deletar"); } @Override public boolean onContextItemSelected(MenuItem item) { if(item.getTitle().equals("Deletar")){ dDAO.open(); dDAO.removerDespesasById(idDespesasSelecionada); dDAO.close(); } onCreate(new Bundle()); return super.onContextItemSelected(item); } @Override protected void onResume() { onCreate(new Bundle()); super.onResume(); } } </code></pre>
    singulars
    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.
 

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