로그로 찍어보면 데이터가 들어간게 나오는데
휴대폰에서 보면 안보이네요 ㅠㅠ 안들어간것 처럼 보여요.
public class PopularFragment extends Fragment{
private boolean isListType = true;
public static PopularFragment newInstance(){
PopularFragment fragment = new PopularFragment();
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if(isListType){
View view = inflater.inflate(R.layout.fragment_list, null);
ListView listview = (ListView)view.findViewById(R.id.listview);
ListArrayAdapter listArrAdapter = new ListArrayAdapter(getActivity(), R.layout.item_contents_list, new ArrayList<ContentData>());
listview.setAdapter(listArrAdapter);
listArrAdapter.clear();
listArrAdapter.add(new ContentData("닌자터틀"));
listArrAdapter.add(new ContentData("7번방의 선물"));
listArrAdapter.add(new ContentData("차차차"));
listArrAdapter.notifyDataSetChanged();
Log.e("log","listArrAdapter.getCount() : "+listArrAdapter.getCount());
return view;
}else{
View view = inflater.inflate(R.layout.fragment_grid, null);
GridView gridview = (GridView)view.findViewById(R.id.gridview);
return view;
}
}
class ListArrayAdapter extends ArrayAdapter<ContentData>{
private ArrayList<ContentData> items;
private Context mContext;
class ViewHolder{
TextView tvName;
}
public ListArrayAdapter(Context context, int txtResId, ArrayList<ContentData> items){
super(context,txtResId, items);
this.mContext = context;
this.items = items;
}
@Override
public int getCount() {
return items.size();
}
@Override
public ContentData getItem(int position) {
return items.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null){
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_contents_list, null);
holder = new ViewHolder();
holder.tvName = (TextView) view.findViewById(R.id.textview_name);
view.setTag(holder);
}else{
holder = (ViewHolder)view.getTag();
}
ContentData thisItem = getItem(position);
Log.e("log", position+" / thisItem.getName() : "+thisItem.getName());
holder.tvName.setText(thisItem.getName());
return view;
}
}
}
fragment_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/coral">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:background="@color/white" />
</LinearLayout>
item_contents_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:id="@+id/textview_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="test"
android:textSize="30dp"
android:gravity="center_vertical"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/icon"/>
</LinearLayout>