0

I have the adapter and want to send some values to another activity by putExtra Inside setOnClickListener Is there a way to do it.

 HireMe.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                context.startActivity(new Intent(context, HireLater.class));

               // intent.putExtra nameText & subjectText

        }
    });

}

My Adapter 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;

}}
Asmahan
  • 129
  • 1
  • 4
  • 9
  • siga este ejemplo que ya esta en stackoverfloe[link](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Isa M Apr 24 '17 at 22:20
  • 1
    @IsaM Please use English – S.R Apr 24 '17 at 22:30
  • 1
    Personally I try to leave this kind of logic out of the adapter and allow the host Activity or Fragment take care of it. I'd suggest using an interface to callback to the activity/fragment with the correct information, then form the intent there. – raisedandglazed Apr 24 '17 at 22:34

1 Answers1

2

How are you going to put an extra in that Intent, if you don't create the variable and use new Intent() directly?

Just change it to the normal way you would do it in every other place.

Intent intent = new Intent(context, HireLater.class);
intent.putExtra("", "");
context.startActivity(intent);

You can get your answer also in this other Stack question: https://stackoverflow.com/a/2091482/7426526

Community
  • 1
  • 1
JMedinilla
  • 481
  • 5
  • 15