@@ -28,20 +28,18 @@ android { | |||||
buildFeatures { | buildFeatures { | ||||
viewBinding true | viewBinding true | ||||
} | } | ||||
sourceSets { | sourceSets { | ||||
main{ | main{ | ||||
res.srcDirs=[ | res.srcDirs=[ | ||||
'src/main/res/layout/datatab/layout', | |||||
'src/main/res/layout/datatab', | 'src/main/res/layout/datatab', | ||||
'src/main/res/layout/from/layout', | |||||
'src/main/res/layout/from', | 'src/main/res/layout/from', | ||||
'src/main/res/layout/item/layout', | |||||
'src/main/res/layout/item', | 'src/main/res/layout/item', | ||||
'src/main/res/layout/toast/layout', | |||||
'src/main/res/layout/toast', | 'src/main/res/layout/toast', | ||||
'src/main/res/layout', | 'src/main/res/layout', | ||||
'src/main/res' | 'src/main/res' | ||||
] | ] | ||||
} | } | ||||
} | } | ||||
@@ -8,33 +8,59 @@ import android.widget.Button; | |||||
import android.widget.TextView; | import android.widget.TextView; | ||||
import androidx.annotation.NonNull; | import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import com.example.bpa.R; | import com.example.bpa.R; | ||||
import com.example.bpa.db.QueryDB; | |||||
import com.example.bpa.db.mode.BPA_MATERIAL; | import com.example.bpa.db.mode.BPA_MATERIAL; | ||||
import java.util.List; | |||||
import com.example.bpa.helper.T; | |||||
import com.example.bpa.view.inteface.MyClickListener; | |||||
public class wl_adapter extends ArrayAdapter<BPA_MATERIAL> { | |||||
import java.util.List; | |||||
public wl_adapter(@NonNull Context context, int resource, @NonNull List<BPA_MATERIAL> objects) { | |||||
/** | |||||
* 物料数据表格 | |||||
*/ | |||||
public class wl_adapter extends ArrayAdapter<BPA_MATERIAL> implements View.OnClickListener { | |||||
/** | |||||
* 内部点击事件 | |||||
*/ | |||||
private MyClickListener mListener; | |||||
/** | |||||
* 物料数据 | |||||
*/ | |||||
public BPA_MATERIAL bpa_material; | |||||
public wl_adapter(@NonNull Context context, int resource, @NonNull List<BPA_MATERIAL> objects,MyClickListener listener) { | |||||
super(context, resource, objects); | super(context, resource, objects); | ||||
mListener = listener; | |||||
} | } | ||||
//每个子项被滚动到屏幕内的时候会被调用 | //每个子项被滚动到屏幕内的时候会被调用 | ||||
@NonNull | @NonNull | ||||
@Override | @Override | ||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { | ||||
BPA_MATERIAL data = (BPA_MATERIAL) getItem(position);//得到当前项选中item实例 | |||||
bpa_material = (BPA_MATERIAL) getItem(position);//得到当前项选中item实例 | |||||
//为每一个子项加载设定的布局 | //为每一个子项加载设定的布局 | ||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.wl_item, parent, false); | View view = LayoutInflater.from(getContext()).inflate(R.layout.wl_item, parent, false); | ||||
//分别获取 image view 和 textview 的实例 | //分别获取 image view 和 textview 的实例 | ||||
TextView name = view.findViewById(R.id.name); | TextView name = view.findViewById(R.id.name); | ||||
// Button button = view.findViewById(R.id.button_item); | |||||
Button button = view.findViewById(R.id.button_item); | |||||
// 设置要显示的图片和文字 | // 设置要显示的图片和文字 | ||||
name.setText(data.name); | |||||
try { | |||||
} catch (Exception e) { | |||||
} | |||||
name.setText(bpa_material.name); | |||||
button.setOnClickListener(this); | |||||
return view; | 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()); | |||||
} | |||||
} | |||||
} | } |
@@ -17,13 +17,14 @@ import com.example.bpa.db.mode.BPA_MATERIAL; | |||||
import com.example.bpa.db.mode.BPA_USER; | import com.example.bpa.db.mode.BPA_USER; | ||||
import com.example.bpa.helper.T; | import com.example.bpa.helper.T; | ||||
import com.example.bpa.view.adapter.wl_adapter; | import com.example.bpa.view.adapter.wl_adapter; | ||||
import com.example.bpa.view.inteface.MyClickListener; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
/** | /** | ||||
* 物料管理 | * 物料管理 | ||||
*/ | */ | ||||
public class wlgl_activity extends AppCompatActivity implements View.OnClickListener{ | |||||
public class wlgl_activity extends AppCompatActivity implements View.OnClickListener, MyClickListener { | |||||
//region 变量 | //region 变量 | ||||
/** | /** | ||||
@@ -98,7 +99,7 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList | |||||
{ | { | ||||
try{ | try{ | ||||
bpa_materials= QueryDB.GetMaterialALL(); | bpa_materials= QueryDB.GetMaterialALL(); | ||||
wl_adapter adapter = new wl_adapter(wlgl_activity.this, R.layout.wl_item, bpa_materials); | |||||
wl_adapter adapter = new wl_adapter(wlgl_activity.this, R.layout.wl_item, bpa_materials,this); | |||||
datatab.setAdapter(adapter); | datatab.setAdapter(adapter); | ||||
}catch(Exception e){ | }catch(Exception e){ | ||||
@@ -139,5 +140,14 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* 接口方法,响应ListView按钮点击事件 | |||||
*/ | |||||
@Override | |||||
public void clickListener(View v,Object data) { | |||||
QueryDB.DeleteMaterial((BPA_MATERIAL)data); | |||||
Initdata(); | |||||
} | |||||
//endregion | //endregion | ||||
} | } |
@@ -0,0 +1,9 @@ | |||||
package com.example.bpa.view.inteface; | |||||
import android.view.View; | |||||
/** | |||||
* 自定义接口,用于回调按钮点击事件到Activity | |||||
*/ | |||||
public interface MyClickListener{ | |||||
public void clickListener(View v,Object data); | |||||
} |
@@ -3,58 +3,50 @@ | |||||
xmlns:android="http://schemas.android.com/apk/res/android" | xmlns:android="http://schemas.android.com/apk/res/android" | ||||
android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
android:layout_height="match_parent" | android:layout_height="match_parent" | ||||
android:background="@mipmap/dpbj" | |||||
android:orientation="horizontal"> | android:orientation="horizontal"> | ||||
<TextView | |||||
android:id="@+id/name" | |||||
android:layout_width="wrap_content" | |||||
<TableLayout | |||||
android:background="@mipmap/bgxz" | |||||
android:layout_width="match_parent" | |||||
android:layout_height="wrap_content" | android:layout_height="wrap_content" | ||||
android:layout_marginLeft="20dp" | |||||
android:layout_alignParentLeft="true" | |||||
android:text="回锅肉" | |||||
android:textColor="@color/foreground" | |||||
android:textSize="@dimen/textSize" /> | |||||
<!-- <TableLayout--> | |||||
<!-- android:layout_marginTop="10dp"--> | |||||
<!-- android:layout_width="match_parent"--> | |||||
<!-- android:layout_height="wrap_content"--> | |||||
<!-- android:gravity="center"--> | |||||
<!-- android:layout_gravity="center"--> | |||||
<!-- android:stretchColumns="0">--> | |||||
<!-- <TableRow--> | |||||
<!-- android:layout_width="fill_parent"--> | |||||
<!-- android:layout_height="wrap_content"--> | |||||
<!-- android:gravity="center_horizontal">--> | |||||
<!-- <RelativeLayout--> | |||||
<!-- android:layout_width="0dp"--> | |||||
<!-- android:layout_height="wrap_content"--> | |||||
<!-- android:layout_weight="1">--> | |||||
<!-- <TextView--> | |||||
<!-- android:id="@+id/name"--> | |||||
<!-- android:layout_width="wrap_content"--> | |||||
<!-- android:layout_height="wrap_content"--> | |||||
<!-- android:layout_marginLeft="20dp"--> | |||||
<!-- android:layout_alignParentLeft="true"--> | |||||
<!-- android:text="回锅肉"--> | |||||
<!-- android:textColor="@color/foreground"--> | |||||
<!-- android:textSize="@dimen/textSize" />--> | |||||
<!-- </RelativeLayout>--> | |||||
<!-- <RelativeLayout--> | |||||
<!-- android:layout_width="0dp"--> | |||||
<!-- android:layout_height="wrap_content"--> | |||||
<!-- android:layout_weight="1">--> | |||||
<!-- <Button--> | |||||
<!-- android:id="@+id/button_item"--> | |||||
<!-- android:text="删除"--> | |||||
<!-- android:background="@drawable/btn_button"--> | |||||
<!-- android:textSize="@dimen/textSize"--> | |||||
<!-- android:textColor="@color/foreground"--> | |||||
<!-- android:layout_marginLeft="20dp"--> | |||||
<!-- android:layout_width="60dp"--> | |||||
<!-- android:layout_height="26dp"--> | |||||
<!-- />--> | |||||
<!-- </RelativeLayout>--> | |||||
android:gravity="center" | |||||
android:layout_gravity="center" | |||||
android:stretchColumns="0"> | |||||
<TableRow | |||||
android:layout_width="fill_parent" | |||||
android:layout_height="wrap_content" | |||||
android:gravity="center_horizontal"> | |||||
<RelativeLayout | |||||
android:layout_width="0dp" | |||||
android:layout_height="match_parent" | |||||
android:layout_weight="1"> | |||||
<TextView | |||||
android:id="@+id/name" | |||||
android:layout_width="wrap_content" | |||||
android:layout_height="wrap_content" | |||||
android:layout_centerVertical="true" | |||||
android:layout_marginLeft="20dp" | |||||
android:layout_alignParentLeft="true" | |||||
android:text="回锅肉" | |||||
android:textColor="@color/foreground" | |||||
android:textSize="@dimen/textSize" /> | |||||
</RelativeLayout> | |||||
<RelativeLayout | |||||
android:layout_width="0dp" | |||||
android:layout_height="match_parent" | |||||
android:layout_weight="1"> | |||||
<Button | |||||
android:id="@+id/button_item" | |||||
android:text="删除" | |||||
android:background="@drawable/btn_button" | |||||
android:textSize="@dimen/textSize" | |||||
android:textColor="@color/foreground" | |||||
android:layout_centerVertical="true" | |||||
android:layout_marginLeft="20dp" | |||||
android:layout_width="60dp" | |||||
android:layout_height="26dp" | |||||
/> | |||||
</RelativeLayout> | |||||
<!-- </TableRow>--> | |||||
<!-- </TableLayout>--> | |||||
</TableRow> | |||||
</TableLayout> | |||||
</RelativeLayout> | </RelativeLayout> |
@@ -165,7 +165,7 @@ | |||||
android:layout_height="wrap_content" | android:layout_height="wrap_content" | ||||
android:layout_marginLeft="20dp" | android:layout_marginLeft="20dp" | ||||
android:layout_alignParentLeft="true" | android:layout_alignParentLeft="true" | ||||
android:text="回锅肉" | |||||
android:text="物料名称" | |||||
android:textColor="@color/dataGridColumnHeaderColor" | android:textColor="@color/dataGridColumnHeaderColor" | ||||
android:textSize="@dimen/textSize" /> | android:textSize="@dimen/textSize" /> | ||||
</RelativeLayout> | </RelativeLayout> | ||||
@@ -194,10 +194,9 @@ | |||||
android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
android:layout_height="match_parent" | android:layout_height="match_parent" | ||||
android:divider="#00000000" | android:divider="#00000000" | ||||
android:dividerHeight="14dp" | |||||
android:paddingLeft="10dp" | |||||
android:paddingRight="10dp" | |||||
android:paddingTop="10dp"/> | |||||
android:dividerHeight="3dp" | |||||
android:layout_marginTop="3dp" | |||||
/> | |||||
</RelativeLayout> | </RelativeLayout> | ||||
</LinearLayout> | </LinearLayout> | ||||
</RelativeLayout> | </RelativeLayout> | ||||