Browse Source

3232323232

master
fyf 1 year ago
parent
commit
c0d6a8d7bf
2 changed files with 23 additions and 24 deletions
  1. +16
    -22
      app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java
  2. +7
    -2
      app/src/main/java/com/example/bpa/view/from/wlgl_activity.java

+ 16
- 22
app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java View File

@@ -20,24 +20,22 @@ import java.util.List;
/**
* 物料数据表格
*/
public class wl_adapter extends ArrayAdapter<BPA_MATERIAL> implements View.OnClickListener {
public class wl_adapter extends ArrayAdapter<BPA_MATERIAL> {
/**
* 内部点击事件
*/
private MyClickListener mListener;
/**
* 物料数据
*/
public BPA_MATERIAL bpa_material;
private List<BPA_MATERIAL> datas;
public wl_adapter(@NonNull Context context, int resource, @NonNull List<BPA_MATERIAL> 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<BPA_MATERIAL> 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());
}
}
}

+ 7
- 2
app/src/main/java/com/example/bpa/view/from/wlgl_activity.java View File

@@ -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
}

Loading…
Cancel
Save