Hi I have developed a Grid view with Images in it, I have written an adapter for it, it worked fine as the grid had just a single image, now I trying to put a text in the grid just below the image, Since then it is crashing , here is the crash log
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
at android.widget.LinearLayout.measureVertical(LinearLayout.java:655)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15479)
at android.widget.GridView.onMeasure(GridView.java:1044)
at android.view.View.measure(View.java:15479)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15479)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15479)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15479)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4828)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2359)
at android.view.View.measure(View.java:15479)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1968)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1214)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1387)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4464)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4895)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
at dalvik.system.NativeStart.main(Native Method)
Here is my custom adapter class
public class ImageAdapter extends BaseAdapter
{
private final String[] subText = {};
Context mContext;
public ImageAdapter(Context _context, String[] subText)
{
super();
mContext = _context;
}
public static String[] mThumbIds ={};
public static String[] mVideoIds = {};
public static final String[] SubText = new String[] {
"text1", "text2","text3", "text4","text1", "text2","text3", "text4" ,"text1", "text2","text3", "text4" ,"text1", "text2","text3", "text4" };
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Add The Image!!!
View gridView;
LayoutInflater inflater = (LayoutInflater)mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = new View(mContext);
gridView = inflater.inflate(R.layout.grid_item,null);
//add Text
TextView textView = (TextView)gridView.findViewById(R.id.grid_item_text);
textView.setText(SubText[position]);
ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
imageView.setImageURI(Uri.parse(mThumbIds[position]));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(150, 150));
return gridView;
}
}
Can anybody plase tell me where exactly I went wrong.