how to change AlertDialog to intent to move to another activity

219 Views Asked by At

I've tried various ways but can't and until I stop here, I've tried it myself with an Intent (Intent intent = new Intent) now I've used this method but it doesn't work then I've also created a new activity and it doesn't work either

@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();
}

}

1

There are 1 best solutions below

0
Ananta Raha On

If you are trying to launch AnotherActivity on button click, change your onClick method like:

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);
    }
});