我已经尝试了各种方法,但不能,直到我停在这里,我已经尝试过它自己与一个意图(Intent Intent = new Intent)现在我已经使用了这个方法,但它不起作用然后我也创建了一个新的活动,它也不起作用
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view= LayoutInflater.from(context).inflate(R.layout.item,viewGroup,false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
MyViewHolder item=(MyViewHolder) viewHolder;
User user=list.get(i);
item.getName().setText(user.getName());
Button edit = item.itemView.findViewById(R.id.edit);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final View mView = LayoutInflater.from(context).inflate(R.layout.activity_update, null);
AlertDialog alertDialog = new AlertDialog.Builder(context)
.setView(mView)
.show();
final DaoSession daoSession;
daoSession = ((MyApp) ((Activity) context).getApplication()).getDaoSession();
Button editupd = alertDialog.findViewById(R.id.submitupdate);
editupd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UserDao userDao = daoSession.getUserDao();
User user1 = new User();
EditText name = mView.findViewById(R.id.name);
EditText address = mView.findViewById(R.id.address);
Button updt = mView.findViewById(R.id.submitupdate);
user1.setId(user.getId());
user1.setName(name.getText().toString());
user1.setAddress(address.getText().toString());
userDao.update(user1);
}
});
}
});
Log.e("name",user.getName());
}
@Override
public int getItemCount() {
return list.size();
}
}
如果你想启动AnotherActivity
按钮点击,改变你的onClick方法,如:
Button edit = item.itemView.findViewById(R.id.edit);
edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Start your activity
Context context = v.getContext();
Intent intent = new Intent(context, AnotherActivity.class);
context.startActivity(intent);
}
});