OnClickListener以微调? ?? [英] OnClickListener to Spinner ? ??

查看:101
本文介绍了OnClickListener以微调? ??的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个OnClickListener到我的微调。

I need an OnClickListener to my Spinner.

我trye​​d一切,我在互联网上找到,但他们没有工作。
请给我一个解决方案:

I tryed everything i found on the internet, but none of them worked. Please give me a solution for this:

得到了我在这里微调:

     spinner = (Spinner)findViewById(R.id.spinner1);

     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource
     (this, R.array.gyerekek_array, R.layout.my_spinner);

     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);



     spinner.setAdapter(adapter);
     spinner.setOnItemSelectedListener(new ItemChooser());

这是my_spinner.xml:

And this is my_spinner.xml:

<?xml version="1.0" encoding="utf-8"?>
   <TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" 
    android:gravity="center_vertical|center_horizontal"
    android:textColor="#000000"
    android:paddingLeft="50dp"
    android:text="Sample Text" 
    android:textStyle="bold"
    android:textSize="31sp"
    >

</TextView>

我trye​​d一切从计算器,一切从互联网上其他人。我只是不能让它...
我不能onClickListener添加到微调的默认TextView的,因为我不使用默认的微调,我有我自己的my_spinner.xml。
事实上,如果我加一个ID到my_spinner.xml里面我的文本视图,我得到一个空指针异常。

I tryed everything from stackoverflow and everything else from the internet. I just cant make it... I cannot add onClickListener to the spinner's default TextView because i dont use the default spinner, i got my own my_spinner.xml. In Fact, if i add an "ID" to my Text View inside the my_spinner.xml i got a null pointer exception.

我甚至tryed添加一个不可见的TextView上盖的微调,但后来只有一个视图可以进行的OnClick有传感器。

I even tryed to add an invisible TextView atop of the Spinner, but then only one view can be sensored by OnClick.

请帮我家伙。

推荐答案

您不能在任何适配器视图中添加一个onclicklistener尝试使用setOntouchlistener希望它会帮助你。

you can't add an onclicklistener on any adapter view try to use setOntouchlistener hope it will help you

spinner = (Spinner)findViewById(R.id.spinner1);

     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource
     (this, R.array.gyerekek_array, R.layout.my_spinner);

     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

     spinner.setOnTouchlistener(this); 

     spinner.setAdapter(adapter);
     spinner.setOnItemSelectedListener(new ItemChooser());

////////////////////////////监听器

//////////////////////////// your listener

public boolean onTouch(View v, MotionEvent event) {
        Log.d("Spinner","clicked");
        return false;
    }

这篇关于OnClickListener以微调? ??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆