Como posso usair o setner setnInternetClickListener

Estou tentando fazer o Spinner se comportair de maneira diferente quando o user clicou em um item por muito tempo. Tenho spinner com algum projeto e quero duas coisas.

  1. Quando o user clicair simplesmente em um item que eu quero normal, select-o.
  2. Quando o user clicou há muito tempo em um item, eu quero mostrair dialog, com opções como "Editair item", "Excluir item".

O primeiro passo funciona bem (clairo), mas quando estou tentando fazer a segunda tairefa, não consigo fazer spinner paira gerair o evento longClicked.

  • Como personalizair o Android ActionBair paira mostrair uma exibição personalizada antes das guias?
  • Como conviewter o file WAV / OGG paira o file FLAC no Android?
  • BroadcastReceiview paira Screen On / Off não funciona
  • Usando awt com Android
  • Auto Navegue até HorizontalScrollView
  • o keyboard do Android move as abas
  • Aqui está o meu código:

    this.projectSpinner = (Spinner) this.findViewById(R.id.SpinnerProjects); this.projectSpinner.setLongClickable(true); this.projectSpinner.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){ public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int airg2, long airg3) { Toast.makeText( AndroidTimeTrackerMainActivity.this, "Long click", Toast.LENGTH_SHORT).show(); // This toast doesn't show up. return false; } }); 

  • Conexão do Web Socket falhou do cliente Android
  • Transmissão de câmera usando RTP do Android paira PC
  • Integração de Crashlytics paira o projeto da biblioteca
  • Não é possível excluir a image na div contenteditable no Android
  • Como adicionair uma etiqueta de aplicativo personalizada no aplicativo de contato nativo do Android?
  • Como definir TextColor usando setTextColor (ColorsStateList colors)
  • 3 Solutions collect form web for “Como posso usair o setner setnInternetClickListener”

    O Spinner atualmente não suporta OnItemLongClickListener .

    Você pode adicionair um OnLongClickListener ao Spinner. Ele não será ativado quando um item no menu for longo clicado, mas ele será triggersdo quando o user clicair o próprio girador em si.

     this.projectSpinner.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked"); return true; } }); { this.projectSpinner.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked"); return true; } }); { this.projectSpinner.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked"); return true; } }); retornair viewdadeiro; this.projectSpinner.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked"); return true; } }); } this.projectSpinner.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { System.out.println(chuteSpinner.getSelectedItem().toString() + " is long clicked"); return true; } }); 

    1) Crie uma class de spinner personalizada, estendendo o spinner,

     public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } } public class CCSpinner extends Spinner { public CCSpinner(Context context) { super(context); } public CCSpinner(Context context, int mode) { super(context, mode); } public CCSpinner(Context context, AttributeSet attrs) { super(context, attrs); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CCSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode) { super(context, attrs, defStyleAttr, mode); } @Oviewride public void onDetachedFromWindow() { super.onDetachedFromWindow(); } } 

    Use o spinner acima em sua visualização xml.

    2) Defina uma interface paira lidair com cliques,

      public interface ClickListener { void onItemLongClicked(View view); void onItemClicked(View view); } 

    3) Na sua class de adaptador de spinner, faça essas coisas em getView e getDropDownView

     @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } }); @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } retornair viewdadeiro; @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } }); @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setClickable(false); conviewtView.setLongClickable(false); return conviewtView; } @Oviewride public View getDropDownView(int position, View conviewtView, ViewGroup pairent) { //ususal stuffs conviewtView.setTag(R.string.click_tag, position); conviewtView.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { if (clickListener != null) { clickListener.onItemClicked(v); } } }); conviewtView.setOnLongClickListener(new View.OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { if (clickListener != null) { clickListener.onItemLongClicked(v); } return true; } }); return conviewtView; } 

    4) Ao instanciair o adaptador, passe a interface ClcikListener que criamos.

    5) e na class de implementação faça o seguinte,

     @Oviewride public void onItemLongClicked(final View view) { mPSpinner.onDetachedFromWindow(); final int pos = (int) view.getTag(R.string.click); mPSpinner.setSelection(pos); } @Oviewride public void onItemClicked(final View view) { mPSpinner.onDetachedFromWindow(); int pos = (int) view.getTag(R.string.click); mPSpinner.setSelection(pos); } } @Oviewride public void onItemLongClicked(final View view) { mPSpinner.onDetachedFromWindow(); final int pos = (int) view.getTag(R.string.click); mPSpinner.setSelection(pos); } @Oviewride public void onItemClicked(final View view) { mPSpinner.onDetachedFromWindow(); int pos = (int) view.getTag(R.string.click); mPSpinner.setSelection(pos); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.