gpt4 book ai didi

java - 无法使用 Intent 启动新 Activity

转载 作者:行者123 更新时间:2023-12-02 11:32:01 25 4
gpt4 key购买 nike

我正在调用一个 Activity ,并将值从适配器传输到下一个 Activity ,这些值已传输,但无法启动该 Activity ,而且也没有错误,只是下一个 Activity 未打开

持有者:

public class ContactReadHolder extends RecyclerView.ViewHolder {

TextView contactName, contactPhone;
ImageButton contactCall;
public ContactReadHolder(View itemView) {
super(itemView);

context =itemView.getContext();

contactName = (TextView) itemView.findViewById(R.id.contact_list_name);
contactPhone = (TextView) itemView.findViewById(R.id.contact_list_phone);
contactCall = (ImageButton) itemView.findViewById(R.id.contact_list_call);
}
}

这是我的适配器代码,我已经在 onBindViewHolder 中实现了监听器,但它仍然不起作用,而且我也在 Holder 类中尝试过

适配器:

public class ContactReadAdapter extends RecyclerView.Adapter<ContactReadAdapter.ContactReadHolder> {

private LayoutInflater layoutInflater;
private List<ContactListModel> contactListModelList;
private Context context;

public ContactReadAdapter(List<ContactListModel> contactListModelList, Context context) {

this.contactListModelList = contactListModelList;
this.context = context;
}


@NonNull
@Override
public ContactReadHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

layoutInflater = LayoutInflater.from(context);
View view = layoutInflater.inflate(R.layout.abc_contact_layout, parent, false);

ContactReadHolder contactReadHolder = new ContactReadHolder(view);
return contactReadHolder;
}

@Override
public void onBindViewHolder(@NonNull final ContactReadHolder holder, int position) {

final TextView contactName, contactPhone;

contactName = holder.contactName;
contactPhone = holder.contactPhone;

contactName.setText(contactListModelList.get(position).getModel_contact_name());
contactPhone.setText(contactListModelList.get(position).getModel_contact_phone());

holder.contactCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Log.d("duit","clicked ");
Intent intent=new Intent(context,OutgoingCallActivity.class);
String string_contactName=holder.contactName.getText().toString();
String string_contactPhone=holder.contactPhone.getText().toString();

Log.d("duit","clicked " + string_contactName +" "+ string_contactPhone);
intent.putExtra("user_name",string_contactName);
intent.putExtra("calleeNumber", string_contactPhone);

context.startActivity(intent);
}
});
}

@Override
public int getItemCount() {
return contactListModelList.size();
}

最佳答案

试试这个

 Intent intent=new Intent(v.getContext(),OutgoingCallActivity.class);
// put extra methods
v.getContext().startActivity(intent);

关于java - 无法使用 Intent 启动新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49225388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com