需求:在OneActivity的适配器中,把Activity的值通过set方法进行传递,然后再通过onItemClick往下传递到另一个Activity。
第一步在适配器中写一个变量,get,set方法:
private int schooltype;
public int getSchooltype() {
return schooltype;
}
public void setSchooltype(int schooltype) {
this.schooltype = schooltype;
}
第二步在Activity中通过adapter的set方法进行赋值:
int schooltype = getIntent().getIntExtra("schooltype", 0);
schoolSelectAdapter.setSchooltype(schooltype);
第三步在适配器的Onclice事件进行往下传递:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
MobclickAgent.onEvent(mContext, AnalyzeStudent.HOME_ACTIVITY);
JsonNewSelectSchool.ResultListBean.ListBean dataItem = getItem((int) id);
Intent starter = new Intent(mContext, SchoolDetailsNewActivity.class);
starter.putExtra(KeyShop.SCHOOL_ID, dataItem.getId() + "");//String类型
starter.putExtra("schooltype", schooltype );//int类型
mContext.startActivity(starter);
}
第四步在另一个Activity进行接收:
schooltype = getIntent().getIntExtra("schooltype", 0);//int类型接收
---------------------------------------------------------华丽的分界线------------------------------------------------------------------------
项目中子包跳转到主包中:
【这是源码对ComponentName的解释,第一个是项目包名,第二个是类的包名
public ComponentName(String pkg, String cls) { if (pkg == null) throw new NullPointerException("package name is null"); if (cls == null) throw new NullPointerException("class name is null"); mPackage = pkg; mClass = cls; }
】
Intent mIntent = new Intent(); ComponentName comp = new ComponentName("com.dyhoa.school", "com.dyhoa.school.HomeActivity"); mIntent.setComponent(comp); startActivity(mIntent);