Я хочу использовать onActivityResult в RecyclerView.Adapter. Но я не понимаю, как этот релиз в моей ситуации. У меня есть динамический RecyclerView.Adapter
RecyclerView.Adapter:
public class SettingsRecyclerAdapter extends RecyclerView.Adapter {
private ArrayList<SettingsTypeModel> dataSet;
Context mContext;
int total_types;
TextInputLayout textInputLayoutIncome;
TextInputLayout textInputLayoutCosts;
EditText editIncome;
EditText editCosts;
public MoneyTypeViewHolder(View itemView) {
super(itemView);
textInputLayoutIncome = (TextInputLayout) itemView.findViewById(R.id.textInputLayoutIncome);
editIncome = (EditText) textInputLayoutIncome.findViewById(R.id.editIncome);
textInputLayoutCosts = (TextInputLayout) itemView.findViewById(R.id.textInputLayoutCosts);
editCosts = (EditText) textInputLayoutCosts.findViewById(R.id.editCosts);
}
}
public static class SendToMailTypeViewHolder extends RecyclerView.ViewHolder {
Switch switchSendMailReport;
public SendToMailTypeViewHolder(View itemView) {
super(itemView);
switchSendMailReport = (Switch) itemView.findViewById(R.id.switchSendMailReport);
}
}
public static class SendToDriveTypeViewHolder extends RecyclerView.ViewHolder {
Switch switchDriveReport;
public SendToDriveTypeViewHolder(View itemView) {
super(itemView);
switchDriveReport = (Switch) itemView.findViewById(R.id.switchDriveReport);
}
}
public SettingsRecyclerAdapter(ArrayList<SettingsTypeModel> data, Context context) {
this.dataSet = data;
this.mContext = context;
total_types = dataSet.size();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType) {
case SettingsTypeModel.TYPE_SEND_TO_MAIL:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_send_to_mail, parent, false);
return new SendToMailTypeViewHolder(view);
case SettingsTypeModel.TYPE_SEND_TO_DRIVE:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.type_send_to_drive, parent, false);
return new SendToDriveTypeViewHolder(view);
}
return null;
}
@Override
public int getItemViewType(int position) {
switch (dataSet.get(position).type) {
case 4:
return SettingsTypeModel.TYPE_SEND_TO_MAIL;
case 5:
return SettingsTypeModel.TYPE_SEND_TO_DRIVE;
default:
return -1;
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int listPosition) {
SettingsTypeModel object = dataSet.get(listPosition);
if (object != null) {
switch (object.type) {
case SettingsTypeModel.TYPE_SEND_TO_MAIL:
((SendToMailTypeViewHolder) holder).switchSendMailReport.setChecked(false);
((SendToMailTypeViewHolder) holder).switchSendMailReport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
} else {
}
}
});
// switchSendMailReport.setChecked(getSwitchSendReportMail());
break;
case SettingsTypeModel.TYPE_SEND_TO_DRIVE:
((SendToDriveTypeViewHolder) holder).switchDriveReport.setChecked(false);
((SendToDriveTypeViewHolder) holder).switchDriveReport.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
((SendToDriveTypeViewHolder) holder).switchDriveReport.setChecked(false);
} else {
}
}
});
break;
}
}
}
@Override
public int getItemCount() {
return dataSet.size();
}
}
Активность:
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_settings);
ArrayList<SettingsTypeModel> list= new ArrayList<>();
list.add(new SettingsTypeModel(SettingsTypeModel.TYPE_SEND_TO_MAIL));
list.add(new SettingsTypeModel(SettingsTypeModel.TYPE_SEND_TO_DRIVE));
SettingsRecyclerAdapter adapter = new SettingsRecyclerAdapter(list,this);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, OrientationHelper.VERTICAL, false);
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerVieww);
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
mRecyclerView.setLayoutManager(linearLayoutManager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mRecyclerView.setClickable(true);
mRecyclerView.setAdapter(adapter);
}
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
Послещелкнув switchSendMailReport или switchDriveReport, мне нужно вызвать функцию onActivityResult .
Как использовать onActivityResult в RecyclerView.Adapter?
Большое спасибо!