按钮 + Spinner onItemSelectedListener 不起作用
我在使用按钮和以编程方式旋转器时遇到问题,因为 onItemSelectedListener 无法正常工作。我一直在这个论坛上进行谷歌搜索和搜索,即使有一些与我相关的问题,我也无法解决它,因为我的布局中没有声明 Spinner。
这是我的布局:
...<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#010D00"
android:paddingTop="5dp"
android:layout_gravity="center_vertical|center_horizontal">
<Button
android:id="@+id/magic_filter"
android:layout_height="fill_parent"
android:layout_width="80dp"
android:text="Mágico"/>
<Button
android:id="@+id/mision_time_filter"
android:layout_height="fill_parent"
android:layout_width="80dp"
android:text="Tiempo"/>
</LinearLayout>...
然后我这样做:
setContentView(R.layout.gig_noloc_list_fragment);
initializeLayout(); // ...(Button) findViewById(R.id.reputation_filter); x4
initializeSpinners();//...magicSpin = new Spinner(this); x4
initializeAdapters();....
magicFil.setOnClickListener(magicListener);
并且
private void initializeAdapters() {
magicAdap = new ArrayAdapter<String>(this, R.layout.gig_noloc_filter_spinner_view, getResources().getStringArray(R.array.magicItems));
magicSpin.setAdapter(magicAdap);
magicSpin.setOnItemSelectedListener(magicSListener);
}
并且
private OnClickListener magicListener = new OnClickListener() {
@Override
public void onClick(View v) {
magicSpin.performClick();
}
};
我
private OnItemSelectedListener magicSListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
Log.v("HELLO", "BYE");
magicFil.setText("HOLA");
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
magicFil.setText("no tira");
}
};
在屏幕或日志上没有收到任何这些消息或文本。
谁能告诉我发生了什么事?
先感谢您。
I'm having trouble using buttons and programmatically spinners, because onItemSelectedListener doesn't work as it has to do properly. I've been googling and searching in this forum, and even there are some problems related to mine, I can't solve it, because I don't have the Spinner declared in my layout.
Here is my layout:
...<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#010D00"
android:paddingTop="5dp"
android:layout_gravity="center_vertical|center_horizontal">
<Button
android:id="@+id/magic_filter"
android:layout_height="fill_parent"
android:layout_width="80dp"
android:text="Mágico"/>
<Button
android:id="@+id/mision_time_filter"
android:layout_height="fill_parent"
android:layout_width="80dp"
android:text="Tiempo"/>
</LinearLayout>...
Then I do this:
setContentView(R.layout.gig_noloc_list_fragment);
initializeLayout(); // ...(Button) findViewById(R.id.reputation_filter); x4
initializeSpinners();//...magicSpin = new Spinner(this); x4
initializeAdapters();....
magicFil.setOnClickListener(magicListener);
and
private void initializeAdapters() {
magicAdap = new ArrayAdapter<String>(this, R.layout.gig_noloc_filter_spinner_view, getResources().getStringArray(R.array.magicItems));
magicSpin.setAdapter(magicAdap);
magicSpin.setOnItemSelectedListener(magicSListener);
}
and
private OnClickListener magicListener = new OnClickListener() {
@Override
public void onClick(View v) {
magicSpin.performClick();
}
};
and
private OnItemSelectedListener magicSListener = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
Log.v("HELLO", "BYE");
magicFil.setText("HOLA");
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
magicFil.setText("no tira");
}
};
I don't get any of these messages or texts on the screen or log.
Anybody can tell me what's happening?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否为元素(旋转器等)分配了布局高度+宽度?如果没有,您可能没有任何可点击的内容。
Do you have a layout height + width assigned to your elements (spinners, etc)? If not, you may not have anything to click.