viewholder android code example

Example 1: viewwillappear android

Activity.onResume

Example 2: viewholder

class PostsVH(itemView : View)
    : RecyclerView.ViewHolder(itemView)
{
    fun bind(get : UserPosts?) {
        itemView.txt_userId.text = get?.userId.toString()
        itemView.txt_id.text = get?.idPost.toString()
        itemView.txt_title.text = get?.title
        itemView.txt_body.text = get?.body
    }
}

Example 3: onbackpressed android

@Override
public void onBackPressed() {
    new AlertDialog.Builder(this)
        .setTitle("Really Exit?")
        .setMessage("Are you sure you want to exit?")
        .setNegativeButton(android.R.string.no, null)
        .setPositiveButton(android.R.string.yes, new OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                WelcomeActivity.super.onBackPressed();
            }
        }).create().show();
}

Tags:

Java Example