diff --git a/app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java b/app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java index 65ac1ad..c82f7b4 100644 --- a/app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java +++ b/app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java @@ -20,24 +20,22 @@ import java.util.List; /** * 物料数据表格 */ -public class wl_adapter extends ArrayAdapter implements View.OnClickListener { +public class wl_adapter extends ArrayAdapter { /** * 内部点击事件 */ private MyClickListener mListener; - /** - * 物料数据 - */ - public BPA_MATERIAL bpa_material; + private List datas; public wl_adapter(@NonNull Context context, int resource, @NonNull List objects,MyClickListener listener) { super(context, resource, objects); mListener = listener; + datas=objects; } //每个子项被滚动到屏幕内的时候会被调用 @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - bpa_material = (BPA_MATERIAL) getItem(position);//得到当前项选中item实例 + BPA_MATERIAL bpa_material = (BPA_MATERIAL) getItem(position);//得到当前项选中item实例 //为每一个子项加载设定的布局 View view = LayoutInflater.from(getContext()).inflate(R.layout.wl_item, parent, false); //分别获取 image view 和 textview 的实例 @@ -45,22 +43,18 @@ public class wl_adapter extends ArrayAdapter implements View.OnCl Button button = view.findViewById(R.id.button_item); // 设置要显示的图片和文字 name.setText(bpa_material.name); - button.setOnClickListener(this); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + try + { + mListener.clickListener(view,bpa_material); + } catch (Exception e) + { + T.show(view.getContext(),"删除物料出错:"+e.getMessage()); + } + } + }); return view; } - - /** - * 传出-->外部 - * @param view - */ - @Override - public void onClick(View view) { - try - { - mListener.clickListener(view,bpa_material); - } catch (Exception e) - { - T.show(view.getContext(),"删除物料出错:"+e.getMessage()); - } - } } \ No newline at end of file diff --git a/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java b/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java index d9629c3..d89803b 100644 --- a/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java +++ b/app/src/main/java/com/example/bpa/view/from/wlgl_activity.java @@ -146,8 +146,13 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList */ @Override public void clickListener(View v,Object data) { - QueryDB.DeleteMaterial((BPA_MATERIAL)data); - Initdata(); + switch (v.getId()) + { + case R.id.button_item://删除按钮 + QueryDB.DeleteMaterial((BPA_MATERIAL)data); + Initdata(); + break; + } } //endregion } \ No newline at end of file