Activity与适配器进行传值

需求:在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);

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@删库跑路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值