import android.content.Context; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; import com.agreeta.firebasedatabasedemo.R; import java.util.ArrayList; import java.util.HashMap; public class TestAdapter extends ArrayAdapter { private Context mContext; private ArrayList<HashMap<String, String>> hashMapArrayList = new ArrayList<>(); public TestAdapter(@NonNull Context context, ArrayList<HashMap<String, String>> list) { super(context, 0 , list); mContext = context; hashMapArrayList = list; } @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { View listItem = convertView; if(listItem == null) listItem = LayoutInflater.from(mContext).inflate(R.layout.like_row,parent,false); TextView release = (TextView) listItem.findViewById(R.id.tv_title); release.setText(hashMapArrayList.get(position).get("key")); return listItem; } }
Try with this example. Here, the "key" is the HashMap key, with which you can set the value for the counter line.
source share