ITKeyword,专注技术干货聚合推荐

注册 | 登录

作为一名基层管理者如何利用情商管理自己和团队(一)

u013970991 2016-08-04

相关推荐:项目管理方法---基层项目经理如何激励自己的团队

激励在哪里都是需要的,对于基层员工来讲,他可能考虑不到公司长远的发展,比较难认同公司长远利益,而与公司共甘苦。这也很容易理解,他们一般都很年

up vote 3 down vote favorite 1

This question already has an answer here:

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>
android spinner share | improve this question asked Nov 10 '12 at 22:13 user1815241 296 2 5 17

marked as duplicate by blahdiblah, Bill the Lizard Mar 11 '13 at 12:32

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

     What version of android are you using? In android 3.0+ I have not noticed the prompt being displayed anymore –  jcw Nov 10 '12 at 22:20      I am currently using 4.1.2. Does that mean that the prompt functionality is deprecated? Is there a better way to accomplish the same thing. –  user1815241 Nov 11 '12 at 5:11 add a comment  | 

1 Answer 1

active oldest votes up vote 4 down vote

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"

share | improve this answer edited Nov 11 '12 at 16:39 answered Nov 11 '12 at 9:37 jcw 3,905 5 23 44      Thank you very much. This was very informative and helpful. I will post my final solution. Craig –  user1815241 Nov 11 '12 at 16:52      FWIW - I attmepted the "button approach" and it worked fine. The functionality was perfect but I really didn't dig much of the UI (too much going on). I then decided to go with the first value of my list-array to have the value "Please Select...". I don't love having "fake" values in my spinner and then have to code around them (e.g. on click of a fake value) but it seems to work fine and the UI is much cleaner. thank you all. –  user1815241 Nov 12 '12 at 3:53      What you are looking for can be done using this stackoverflow.com/a/14546126/452487 –  jaydeepw May 7 '14 at 5:55 add a comment  | 

Not the answer you're looking for? Browse other questions tagged android spinner or ask your own question.

相关推荐:一个研发团队管理者的痛苦:如何保持激情?

今天有个朋友来公司拜访,有幸一起参与探讨了一些问题。其实他是带着问题而来的,就是公司现在面临着一个困扰的难题:发展到一定规模,如何使得团队

注:本文原是采用视频与现场练习的方式进行分享,采用文字分享在内容上将会有一些缩减在我们正式分享之前,先举一个我在团队中实验的案例来说明情商是什么。 我给团队中的每人都发了一张A4纸...

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。