Last active
December 16, 2015 04:59
-
-
Save markbratanov/5380875 to your computer and use it in GitHub Desktop.
GridAdapter for StackOverflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocationModelGridAdapter extends BaseAdapter { | |
private class ViewHolder { | |
public ImageView imageView; | |
public TextView textView; | |
} | |
private lineModel[] mLine; | |
private LayoutInflater mInflater; | |
public LocationModelGridAdapter(Context context, lineModel[] locations) { | |
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
mLine = locations; | |
Log.v("GetViewAdapter", "mline has a length of: " + mLine); | |
} | |
@Override | |
public int getCount() { | |
if (mLine != null) { | |
Log.v("GetViewAdapter", "mline has a length of: " + mLine.length); | |
return mLine.length; | |
} | |
return 0; | |
} | |
@Override | |
public Object getItem(int position) { | |
if (mLine != null && position >= 0 && position < getCount()) { | |
return mLine[position]; | |
} | |
return null; | |
} | |
@Override | |
public long getItemId(int position) { | |
Log.v("GetViewAdapter", "mline has a length of: " + mLine[position].col_id); | |
if (mLine != null && position >= 0 && position < getCount()) { | |
return mLine[position].col_id; | |
} | |
return 0; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
View view = convertView; | |
ViewHolder viewHolder; | |
if (view == null || view.getTag() == null) { | |
view = mInflater.inflate(R.layout.grid_view, parent, false); | |
viewHolder = new ViewHolder(); | |
// viewHolder.imageView = (ImageView) view.findViewById(R.id.grid_image); | |
viewHolder.textView = (TextView) view.findViewById(R.id.grid_label); | |
view.setTag(viewHolder); | |
Log.v("GetViewAdapter", "View is null, setup viewholder"); | |
}else { | |
viewHolder = (ViewHolder) view.getTag(); | |
Log.v("GetViewAdapter", "View is not null, setup viewholder"); | |
} | |
lineModel locationModel = mLine[position]; | |
Log.v("GetViewAdapter", "mline has a position of: " + position); | |
Log.v("GetViewAdapter", "mline has a name of: " + locationModel.col_line); | |
if(locationModel!=null) { | |
viewHolder.textView.setText(locationModel.col_line); | |
} | |
return view; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04-13 20:55:13.612: V/GetViewAdapter(23329): mline has a length of: 4 | |
04-13 20:55:13.620: V/GetViewAdapter(23329): View is null, setup viewholder | |
04-13 20:55:13.620: V/GetViewAdapter(23329): mline has a position of: 0 | |
04-13 20:55:13.620: V/GetViewAdapter(23329): mline has a name of: B | |
04-13 20:55:13.620: D/AndroidRuntime(23329): Shutting down VM | |
04-13 20:55:13.620: W/dalvikvm(23329): threadid=1: thread exiting with uncaught exception (group=0x40dd8930) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): FATAL EXCEPTION: main | |
04-13 20:55:13.644: E/AndroidRuntime(23329): java.lang.NullPointerException | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at com.idealiner.metrosleepuniversal.adapter.LocationModelGridAdapter.getView(LocationModelGridAdapter.java:99) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.AbsListView.obtainView(AbsListView.java:2159) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.GridView.onMeasure(GridView.java:1040) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.LinearLayout.onMeasure(LinearLayout.java:590) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1381) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.LinearLayout.measureVertical(LinearLayout.java:847) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4827) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.View.measure(View.java:15513) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.Choreographer.doCallbacks(Choreographer.java:562) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.Choreographer.doFrame(Choreographer.java:532) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.os.Handler.handleCallback(Handler.java:725) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.os.Handler.dispatchMessage(Handler.java:92) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.os.Looper.loop(Looper.java:137) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at android.app.ActivityThread.main(ActivityThread.java:5039) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at java.lang.reflect.Method.invokeNative(Native Method) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at java.lang.reflect.Method.invoke(Method.java:511) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) | |
04-13 20:55:13.644: E/AndroidRuntime(23329): at dalvik.system.NativeStart.main(Native Method) | |
04-13 20:55:13.659: D/dalvikvm(23329): GC_CONCURRENT freed 261K, 4% free 9062K/9356K, paused 5ms+2ms, total 34ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment