編輯:關於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>
用U盤安裝Ubuntu系統,u盤ubuntu用U盤安裝Ubuntu,需制作一個Ubuntu的U盤安裝盤,最為方便和可靠的制作方法是在Linux系統下使用dd命令,具體如下
React Native控件之PullToRefreshViewAndroid下拉刷新組件講解 (一)前言 今天我們一起來看一下PullToRefreshViewAn
Android之ProgressBar初步應用,androidprogressbar這裡利用 ProgressBar 即時顯示下載進度。 途中碰到的問題: 1、主線程中不
android 實現漫天飛舞雪花以及下雨天的效果 前言: 這個效果實現的原作者是國外一位大神。我在其基礎上測試,以及在代碼上加了不少注釋,以及局部修改。後面我有根據漫