在res/layout目录中新建choose_area.xml
代码如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#fff " >
<RelativeLayout
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary">
<TextView
android:id="@+id/title_text"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="20sp"
android:textColor="#fff"
android:layout_centerInParent="true" />
<Button
android:id="@+id/back_button"
android:layout_height="25dp"
android:layout_width="25dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
/>
</RelativeLayout>
<ListView
android:id="@+id/list_view"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
接下来关键的一步,我们需要编写用于遍历省市县数据的碎片
代码如下
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.example.dong.myapplication.Util.HttpUtil;
import com.example.dong.myapplication.Util.Utility;
import com.example.dong.myapplication.db.City;
import com.example.dong.myapplic