我很新的android开发,我似乎有我无法理解的问题。我有一个微调和值越来越设置得很好,但我的提示没有出现。我曾试图设定这两个XML和Java code和没有一个很好的工作。下面是我的配置。我觉得我失去了一些东西基本的,但我不知道它是什么呢。
任何帮助将是AP preciated。克雷格
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#000000>
<微调
机器人:ID =@ + ID /乐队
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:layout_marginTop =72dp
机器人:提示=@字符串/ year_prompt
机器人:文字颜色=#F0F0F0/>
<微调
机器人:ID =@ + ID / spinner1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_alignParentRight =真
机器人:layout_alignParentTop =真
机器人:layout_marginTop =28dp
机器人:项=@阵列/ year_array
机器人:提示=@字符串/ year_prompt
机器人:文字颜色=#F0F0F0/>
< / RelativeLayout的>
<字符串名称=year_prompt>选择年份< /串>
<字符串数组名=year_array>
<项目> 2000< /项目>
<项目> 2001年< /项目>
<项目> 2002< /项目>
<项目> 2003< /项目>
<项目> 2004年< /项目>
<项目> 2005< /项目>
< /字符串数组>
解决方案
这是你的晋升没有显示的原因是因为在Android的3.0+,对于提示没有空间。
这是一个截屏的旋转器pre 3.0
提示符是在顶部,在那里说选择了一个国家,屏幕截图的 http://www.mkyong.com/android/android-spinner-drop-down-list-example/
所以提示不再显示。
有几种可能性。
首先,你可以只在你的名单阵列
,也说了同样的事情,你的提示
否则,你可以使用一个按钮,创建一个下拉从该列表中。
首先,在布局一个按钮代替你的微调,并给它,你给你的文字提示
然后把你的产品清单上yoour微调到一个名为 optionmenu.xml
然后声明您的按钮,并设置了一个 onClickListener
吧。
里面那个方法,把下面的code
在foutrh行,您指定的布局是你的optionmenu布局
公共无效showPopup(视图v){
PopupMenu的弹出=新PopupMenu的(这一点,V);
MenuInflater充气= popup.getMenuInflater();
inflater.inflate(R.layout.optionmenu,popup.getMenu());
popup.show();
} 当你调用这个方法,你需要做以下
查看P =(查看)findViewById(R.id.spinner按钮);
showPopup(对);
在code这个价格,查看p是在该位置要显示菜单的右上角的视图。因此,在这种情况下,这将是您的按钮
一看便知这里实现它 - Android的菜单code不工作
和每案例:......
语句,把它设置你的按钮文本作为一个字符串行
案例R.id.item1:
button.setText(ITEM1);
>
有一些其他的好的解决办法在这里 -
How做一个Android微调与初始文本和QUOT;选择一个"
I am very new to android development and I seem to have an issue that I cannot understand. I have a spinner and the values are getting set just fine but my prompt is not appearing. I have attempted to set this in both the xml and the java code and neither one works at all. Below is my configuration. I feel that I am missing something fundamental but I don't know what it is yet.
Any help would be appreciated. Craig
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<Spinner
android:id="@+id/band"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="72dp"
android:prompt="@string/year_prompt"
android:textColor="#F0F0F0" />
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="28dp"
android:entries="@array/year_array"
android:prompt="@string/year_prompt"
android:textColor="#F0F0F0" />
</RelativeLayout>
<string name="year_prompt">Select A Year</string>
<string-array name="year_array">
<item >2000</item>
<item >2001</item>
<item >2002</item>
<item >2003</item>
<item >2004</item>
<item >2005</item>
</string-array>
解决方案
The reason that your promoted is not showing is because in android 3.0+, there is no space for the prompt.
This is a screen shot of a spinner pre 3.0
The prompt is at the top, where is says "Chose a Country", screen shot from http://www.mkyong.com/android/android-spinner-drop-down-list-example/
So the prompt is no longer shown.
There are a few possibilities.
First, you could just add an item at the top of your list-array
, that says the same thing as your prompt
Otherwise you could use a button and create a drop down list from that.
First, in your layout replace your spinner with a button, and give it the text that you gave your prompt
Then move your list of items on yoour spinner to a file called optionmenu.xml
Then declare your button and set up an onClickListener
for it.
Inside that method, put the following code
On the foutrh line, the layout that you specify is your optionmenu layout
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.layout.optionmenu, popup.getMenu());
popup.show();
} When you call this method, you need to do the following
View p = (View)findViewById(R.id.spinner button);
showPopup(p);
In this price of code, View p is the view at the location that you want to show the top corner of the menu. So in this case, it will be your button
See the answer here to implement it - android menu code not working
And in each case:.....
statement, put a line that sets your button text as a string.
case R.id.item1:
button.setText("item1");
>
There are some other good solutions here -
How to make an Android Spinner with initial text "Select One"
相关推荐
最新文章