diff --git a/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java new file mode 100644 index 0000000..0f50618 --- /dev/null +++ b/app/src/main/java/org/ntlab/acanthus_client/views/userpage/UserListViewAdapter.java @@ -0,0 +1,73 @@ +package org.ntlab.acanthus_client.views.userpage; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.TextView; + +import org.ntlab.acanthus_client.R; + +import java.util.ArrayList; + +public class UserListViewAdapter extends BaseAdapter { + + private final LayoutInflater inflater; + private int layoutId; + private ArrayList nameList = new ArrayList<>(); + + //参照保存データ + static class ViewHolder { + TextView textViewUid; + } + + public UserListViewAdapter(Context context, int layoutId, ArrayList name) { + super(); + this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + this.layoutId = layoutId; + this.nameList = name; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + ViewHolder viewHolder; + //Viewのinflate(拡張) + if (convertView == null) { + //fragment_edit.xmlにlistView用のレイアウトを入れ込む + convertView = inflater.inflate(layoutId, parent, false); + //ViewHolderの生成とレイアウト内テキストのセット + viewHolder = new UserListViewAdapter.ViewHolder(); + viewHolder.textViewUid = convertView.findViewById(R.id.followOrFollowerUid); + convertView.setTag(viewHolder); + } else { + //既に初期セットの処理がされている場合、再利用する + viewHolder = (UserListViewAdapter.ViewHolder) convertView.getTag(); + } + + //ViewHolder内のtextViewName,Dateに各ポジションのデータをセット + if (nameList != null) viewHolder.textViewUid.setText(nameList.get(position)); + + return convertView; + } + + public void setNameList(ArrayList nameList) { + this.nameList = nameList; + } + + @Override + public int getCount() { + return nameList.size(); + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + +}