2727import android .view .ViewGroup ;
2828import android .widget .AbsListView ;
2929import android .widget .BaseAdapter ;
30+ import android .widget .GridView ;
3031import android .widget .ImageView ;
3132import android .widget .ListView ;
3233import android .widget .TextView ;
@@ -104,10 +105,12 @@ public int getItemViewType(int position) {
104105 @ Override
105106 public View getView (int position , View convertView , ViewGroup parent ) {
106107 View view = convertView ;
108+ boolean isGridView = parent instanceof GridView ;
107109 if (view == null ) {
108110 LayoutInflater inflator = (LayoutInflater ) mContext
109111 .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
110- view = inflator .inflate (R .layout .list_item , null );
112+ view = isGridView ? inflator .inflate (R .layout .grid_item , null ) :
113+ inflator .inflate (R .layout .list_item , null );
111114 }
112115 if (mFiles != null && mFiles .length > position && mFiles [position ] != null ) {
113116 File file = mFiles [position ];
@@ -130,17 +133,21 @@ public View getView(int position, View convertView, ViewGroup parent) {
130133 }
131134 fileIcon .setTag (file .hashCode ());
132135
136+ ImageView checkBoxV = (ImageView ) view .findViewById (R .id .custom_checkbox );
133137 TextView fileSizeV = (TextView ) view .findViewById (R .id .file_size );
134138 TextView fileSizeSeparatorV = (TextView ) view .findViewById (R .id .file_separator );
135- TextView lastModV = (TextView ) view .findViewById (R .id .last_mod );
136- ImageView checkBoxV = (ImageView ) view .findViewById (R .id .custom_checkbox );
137- lastModV .setVisibility (View .VISIBLE );
138- lastModV .setText (DisplayUtils .getRelativeTimestamp (mContext , file .lastModified ()));
139+ if (!isGridView ) {
140+ TextView lastModV = (TextView ) view .findViewById (R .id .last_mod );
141+ lastModV .setVisibility (View .VISIBLE );
142+ lastModV .setText (DisplayUtils .getRelativeTimestamp (mContext , file .lastModified ()));
143+ }
139144
140145 if (!file .isDirectory ()) {
141- fileSizeSeparatorV .setVisibility (View .VISIBLE );
142- fileSizeV .setVisibility (View .VISIBLE );
143- fileSizeV .setText (DisplayUtils .bytesToHumanReadable (file .length ()));
146+ if (!isGridView ) {
147+ fileSizeSeparatorV .setVisibility (View .VISIBLE );
148+ fileSizeV .setVisibility (View .VISIBLE );
149+ fileSizeV .setText (DisplayUtils .bytesToHumanReadable (file .length ()));
150+ }
144151
145152 AbsListView parentList = (AbsListView ) parent ;
146153 if (parentList .getChoiceMode () == ListView .CHOICE_MODE_NONE ) {
@@ -192,8 +199,10 @@ public View getView(int position, View convertView, ViewGroup parent) {
192199 }
193200
194201 } else {
195- fileSizeSeparatorV .setVisibility (View .GONE );
196- fileSizeV .setVisibility (View .GONE );
202+ if (!isGridView ) {
203+ fileSizeSeparatorV .setVisibility (View .GONE );
204+ fileSizeV .setVisibility (View .GONE );
205+ }
197206 checkBoxV .setVisibility (View .GONE );
198207 }
199208
0 commit comments