android界面开发

关于界面控件的学习3【spinner、autocompletetextview...

Spinner控件

效果如下:

 

 

使用Spinner控件分为三个步骤:

1.修改res/layout/main.xml 添加Spinner控件

    <Spinner
        android:id="@+id/sp1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/planet_prompt"
    />

2.制作弹出菜单的数据源,该数据源可以来自xml,可以自己写Adapter接口(以后学习)
在 res/values修改strings.xml 添加

<string name="planet_prompt">Choose a planet</string>

在 res/values下新建array.xml

<resources>

    <string-array name="planets">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
    </string-array>
   
</resources>

3.声明并实例化spinner类

Spinner sp=(Spinner)this.findViewById(R.id.sp1);ArrayAdapter adapter=ArrayAdapter.createFromResource(this, R.array.planets, android.R.layout.simple_spinner_dropdown_item);

sp.setAdapter(adapter);

AutoCompleteTextView控件

效果如下:

 

 

使用AutoCompleteTextView控件分为三个步骤:

1.修改res/layout/main.xml 添加AutoCompleteTextView控件

<AutoCompleteTextView
    android:id="@+id/ac1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
   />

2.定义AutoComplete的字符串

    static final String[] androidwords = new String[]{
    "yao","yuan","yaoyuanhua","yyh","yoganka","yaoyh","yaoandroid","gk14","gk1","g2"
    };

3.声明并实例化AutoCompleteTextView类

        AutoCompleteTextView ac=(AutoCompleteTextView)this.findViewById(R.id.ac1);
        ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,androidwords);
        ac.setAdapter(adapter);

NotificationBar控件

 

 

shownotification("Hello AndroidQQ群697668来新的消息了");

private void shownotification(String tab)
{
   NotificationManager barmanager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
   Notification msg=new android.app.Notification(android.R.drawable.stat_notify_chat,tab,System.currentTimeMillis());
  
   PendingIntent contentIntent=PendingIntent.getActivity(this, 0, new Intent(this,YaoTest.class), PendingIntent.FLAG_ONE_SHOT);
   msg.setLatestEventInfo(this, "是的,you make it", "yes", contentIntent);
   barmanager.notify(0, msg);
}

为了您的安全,请只打开来源可靠的网址

打开网站    取消

来自: http://hi.baidu.com/gk14/blog/item/b2f7083396ee8df41b4cff2a.html

posted @ 2012-06-25 11:21  a780397897  阅读(115)  评论(0编辑  收藏  举报