編輯:Android開發實例
代碼如下:
Java code:
package zye.client.Client;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
public class cityset extends Activity{
private String[] province = new String[] {"直轄市", "特別行政區","黑龍江"};
private String[] city = new String[]{"北京","上海","天津","重慶"};
private String[][] pandc = new String[][]{{"北京","上海","天津","重慶"},{"香港","澳
門"},{"哈爾濱","齊齊哈爾","牡丹江","大慶","伊春","雙鴨山","鶴崗","雞西","佳木斯","七台河","黑河","綏化","大興安嶺"}};
private Spinner sp;
private Spinner sp2;
private Context context;
ArrayAdapter<String> adapter ;
ArrayAdapter<String> adapter2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cityset);
context = this;
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, province);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp = (Spinner) findViewById(R.id.province);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(selectListener);
adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, city);
adapter2.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
sp2 = (Spinner) findViewById(R.id.city);
sp2.setAdapter(adapter2);
}
private OnItemSelectedListener selectListener = new OnItemSelectedListener(){
public void onItemSelected(AdapterView parent, View v, int position,long id){
int pos = sp.getSelectedItemPosition();
adapter2 = new ArrayAdapter<String>
(context,android.R.layout.simple_spinner_item, pandc[pos]);
sp2.setAdapter(adapter2);
}
public void onNothingSelected(AdapterView arg0){
}
};
}
xml code:
<?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="#FFFFFF"
>
<Spinner android:id="@+id/province"
android:layout_width="fill_parent"
android:layout_height="45px"
android:layout_marginLeft="75px"
android:layout_marginRight="20px"
android:layout_marginTop="7px"
android:drawSelectorOnTop="true"
android:layout_alignParentRight="true"
/>
<Spinner android:id="@+id/city"
android:layout_width="fill_parent"
android:layout_height="45px"
android:layout_marginLeft="75px"
android:layout_marginRight="20px"
android:layout_marginTop="3px"
android:drawSelectorOnTop="true"
android:layout_alignParentRight="true"
android:layout_below="@id/province"
/>
</RelativeLayout>
Android應用程序可以在許多不同地區的許多設備上運行。為了使應用程序更具交互性,應用程序應該處理以適合應用程序將要使用的語言環境方面的文字,數字,文件等。在本章中,我
在android中,LayoutInflater有點類似於Activity的findViewById(id),不同的是LayoutInflater是用來找layo
登錄應用程序的屏幕,詢問憑據登錄到一些特定的應用。可能需要登錄到Facebook,微博等本章介紹了,如何創建一個登錄界面,以及如何管理安全問題和錯誤嘗試。首先,必須定義兩
最近一直在調用微信的API,卻發現一直調用不成功,糾結了好久,各方面找教程,找官方,官方裡的文檔也只是寫得很模糊,說是按三步走。 1、申請App_ID