林製作UI喜歡的圖片: Sketch充氣2個佈局上的GridView項= CRASH :(
所以,當我點擊它,改變它的內容放到一個小菜單一個gridview項
?什麼是處理這個正確的方式我的解決辦法2點佈局,膨脹的項目上點擊, 與刷新:adapter.notifyDataSetChanged();
它運作良好unti你向下滾動(直到物品出現在視線之外)然後崩潰。
這是我getView()代碼:
public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; RecordHolder holder = null; Item item = data.get(position); LayoutInflater inflater = ((Activity) context).getLayoutInflater(); if (row == null) { row = inflater.inflate(layoutResourceId, parent, false); holder = new RecordHolder(); holder.txtTitle = (TextView) row.findViewById(R.id.item_text); holder.imageItem = (ImageView) row.findViewById(R.id.item_image); row.setTag(holder); } else { holder = (RecordHolder) row.getTag(); } if(item.showMenu == true && item.menuShown == false) { item.menuShown = true; row = inflater.inflate(layoutResourceId_menu, parent, false); holder = new RecordHolder(); holder.button1 = (Button) row.findViewById(R.id.button1); holder.button2 = (Button) row.findViewById(R.id.button2); row.setTag(holder); } if(item.showMenu == true && item.menuShown == true) { holder.button1.setText("asdsad"); holder.button2.setText("asdasdd"); } if(item.showMenu == false && item.menuShown == true) { row = inflater.inflate(layoutResourceId, parent, false); holder = new RecordHolder(); holder.txtTitle = (TextView) row.findViewById(R.id.item_text); holder.imageItem = (ImageView) row.findViewById(R.id.item_image); row.setTag(holder); holder.txtTitle.setText(item.getTitle()); holder.imageItem.setImageBitmap(item.getImage()); } if(item.showMenu == false && item.menuShown == false) { holder.txtTitle.setText(item.getTitle()); holder.imageItem.setImageBitmap(item.getImage()); } return row;
}
不管我嘗試它總是崩潰。 我在做這個對嗎?
UPDATE 這裏是logcat的:
06-21 17:37:39.735 3308-3308/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.menu_grid_view_page, PID: 3308
java.lang.NullPointerException
at com.example.menu_grid_view_page.CustomGridViewAdapter.getView(CustomGridViewAdapter.java:91)
at android.widget.AbsListView.obtainView(AbsListView.java:2240)
at android.widget.GridView.makeAndAddView(GridView.java:1345)
at android.widget.GridView.makeRow(GridView.java:345)
at android.widget.GridView.fillDown(GridView.java:287)
at android.widget.GridView.fillGap(GridView.java:247)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5136)
at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4247)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5081)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
您可以發佈與崩潰的logcat的輸出? – michaelcarrano
我知道了! ILL嘗試將它添加到我的信息 – user2551102