我有适配器并希望通过putExtra
内部setOnClickListener
向其他活动发送一些值。有没有办法实现。
HireMe.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
context.startActivity(new Intent(context, HireLater.class));
// intent.putExtra nameText & subjectText
}
});
}
我的适配器HierAdapter.java
public class HireAdapter extends ArrayAdapter<HireItem>{
Context context;
public HireAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<HireItem> objects) {
super(context, resource, objects);
this.context = context;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
if (convertView == null){
convertView = ((Activity)getContext()).getLayoutInflater()
.inflate(R.layout.list_item_teachers,parent,false);
Button HireMe = (Button) convertView.findViewById(R.id.hire_me);
HireMe.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
context.startActivity(new Intent(context, HireLater.class));
// intent.putExtra nameText & subjectText
}
});
}
HireItem teacherItem = getItem(position);
TextView nameText = (TextView)convertView.findViewById(R.id.result_name);
TextView subjectText = (TextView)convertView.findViewById(R.id.result_subject);
TextView levelText = (TextView)convertView.findViewById(R.id.level);
TextView mCity = (TextView)convertView.findViewById(R.id.result_city);
TextView mContact = (TextView)convertView.findViewById(R.id.result_phone);
TextView mQualification = (TextView)convertView.findViewById(R.id.Qua_teacher);
TextView mSalary = (TextView)convertView.findViewById(R.id.salary);
TextView mExperience = (TextView)convertView.findViewById(R.id.exTea);
//
nameText.setText(teacherItem.getResult_name());
subjectText.setText(teacherItem.getResult_subject());
levelText.setText(teacherItem.getResult_level());
mCity.setText(teacherItem.getResult_city());
//
mContact.setText(teacherItem.getResult_mobile());
mQualification.setText(teacherItem.getResult_qualification());
mSalary.setText(teacherItem.getResult_salary());
mExperience.setText(teacherItem.getResult_experince());
return convertView;
}}
答案 0 :(得分:2)
如果你不创建变量并直接使用Intent
,你将如何在new Intent()
中增加额外费用?
只需将其更改为您在其他地方执行此操作的正常方式。
Intent intent = new Intent(context, HireLater.class);
intent.putExtra("", "");
context.startActivity(intent);
您也可以在其他Stack问题中获得答案:https://stackoverflow.com/a/2091482/7426526