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是哪里确定的?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。