Last active
May 27, 2019 17:51
-
-
Save Shivamdhuria/22661084b2f2f3c8e653ff2a4785e45c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> { | |
private ArrayList<String> mTaskNames; | |
private Context mContext; | |
public RecyclerViewAdapter(Context mContext, ArrayList<String> mTaskNames) { | |
this.mTaskNames = mTaskNames; | |
this.mContext = mContext; | |
} | |
@NonNull | |
@Override | |
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { | |
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_layout, viewGroup, false); | |
ViewHolder holder = new ViewHolder(view); | |
return holder; | |
} | |
@Override | |
public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) { | |
viewHolder.taskNameTextView.setText(mTaskNames.get(i)); | |
final TextView statusTextView = viewHolder.statusTextView; | |
final ProgressBar progressBar = viewHolder.progressBar; | |
viewHolder.parentLayout.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(mContext, mTaskNames.get(i), Toast.LENGTH_SHORT).show(); | |
runTask("Task No" + i, statusTextView, progressBar); | |
} | |
}); | |
} | |
@Override | |
public int getItemCount() { | |
return mTaskNames.size(); | |
} | |
public class ViewHolder extends RecyclerView.ViewHolder { | |
TextView taskNameTextView; | |
ProgressBar progressBar; | |
TextView statusTextView; | |
LinearLayout parentLayout; | |
public ViewHolder(@NonNull View itemView) { | |
super(itemView); | |
taskNameTextView = itemView.findViewById(R.id.task_name); | |
progressBar = itemView.findViewById(R.id.progressBar); | |
statusTextView = itemView.findViewById(R.id.status); | |
parentLayout = itemView.findViewById(R.id.parent_layout); | |
} | |
} | |
private void runTask(String taskName, TextView statusTextView, ProgressBar progressBar) { | |
Task task = new Task(mContext, taskName, progressBar, statusTextView); | |
Manager.getManagerInstance().runTask(task); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment