public class ChooseAreaActivity extends Activity {
public static final int LEVEL_PROVINCE = 0;
public static final int LEVEL_CITY = 1;
public static final int LEVEL_COUNTY = 2;
......
private List provinceList;
private List cityList;
private List countyList;
private Province selectedProvince;
private City selectedCity;
/**
* 当前选中的级别
*/
private int currentLevel;
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.choose_area);
.......
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) {
if (currentLevel == LEVEL_PROVINCE) {
selectedProvince = provinceList.get(index);
queryCities();
} else if (currentLevel == LEVEL_CITY) {
selectedCity = cityList.get(index);
queryCounties();
}
}
});
queryProvinces();//加载省级数据
}
以上代码我是按照书上敲的,其中有一点我不理解:类中的3个常量 LEVEL_PROVINCE,LEVEL_CITY,LEVEL_COUNTY,如何在点击一个ListVIew的item的时候知道我是在点击省级别、市级别或是县级别的item?_在onItemClick方法中有判断语句if(currentlevel ==..),这个currentlevel是哪里确定的?