Commit 254957f2 by Paktalin

Minor refactoring

parent 9d2a7e51
package com.paktalin.vocabularynotebook;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.paktalin.vocabularynotebook.pojo.WordItemPojo;
import java.util.List;
public class VocabularyAdapter extends RecyclerView.Adapter<VocabularyAdapter.ViewHolder> {
private static final String TAG = "VN/" + VocabularyAdapter.class.getSimpleName();
private List<WordItemPojo> wordItems;
public VocabularyAdapter(List<WordItemPojo> wordItems) {
this.wordItems = wordItems;
Log.d(TAG, "wordItems: " + wordItems);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
WordItemPojo item = wordItems.get(position);
Log.d(TAG, "bind item: " + item);
holder.tvWord.setText(item.getWord());
holder.tvTranslation.setText(item.getTranslation());
}
@Override
public int getItemCount() {
return wordItems.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView tvWord, tvTranslation;
ViewHolder(View itemView) {
super(itemView);
tvWord = itemView.findViewById(R.id.tvWord);
tvTranslation = itemView.findViewById(R.id.tvTranslation);
}
}
}
package com.paktalin.vocabularynotebook
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.paktalin.vocabularynotebook.pojo.WordItemPojo
class VocabularyAdapter(private val wordItems: List<WordItemPojo>) : RecyclerView.Adapter<VocabularyAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.word_item, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val item = wordItems[position]
holder.tvWord.text = item.word
holder.tvTranslation.text = item.translation
}
override fun getItemCount(): Int {
return wordItems.size
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
var tvWord: TextView = itemView.findViewById(R.id.tvWord)
var tvTranslation: TextView = itemView.findViewById(R.id.tvTranslation)
}
companion object { private val TAG = "VN/" + VocabularyAdapter::class.java.simpleName }
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment