Browse Source

3232323232131212

master
fyf 1 year ago
parent
commit
533e548ab4
6 changed files with 107 additions and 73 deletions
  1. +2
    -4
      app/build.gradle
  2. +37
    -11
      app/src/main/java/com/example/bpa/view/adapter/wl_adapter.java
  3. +12
    -2
      app/src/main/java/com/example/bpa/view/from/wlgl_activity.java
  4. +9
    -0
      app/src/main/java/com/example/bpa/view/inteface/MyClickListener.java
  5. +43
    -51
      app/src/main/res/layout/datatab/layout/wl_item.xml
  6. +4
    -5
      app/src/main/res/layout/from/layout/activity_wlgl.xml

+ 2
- 4
app/build.gradle View File

@@ -28,20 +28,18 @@ android {
buildFeatures {
viewBinding true
}

sourceSets {
main{
res.srcDirs=[
'src/main/res/layout/datatab/layout',
'src/main/res/layout/datatab',
'src/main/res/layout/from/layout',
'src/main/res/layout/from',
'src/main/res/layout/item/layout',
'src/main/res/layout/item',
'src/main/res/layout/toast/layout',
'src/main/res/layout/toast',
'src/main/res/layout',
'src/main/res'
]

}
}



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

@@ -8,33 +8,59 @@ import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.bpa.R;
import com.example.bpa.db.QueryDB;
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);
mListener = listener;
}
//每个子项被滚动到屏幕内的时候会被调用
@NonNull
@Override
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);
//分别获取 image view 和 textview 的实例
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;
}

/**
* 传出-->外部
* @param view
*/
@Override
public void onClick(View view) {
try
{
mListener.clickListener(view,bpa_material);
} catch (Exception e)
{
T.show(view.getContext(),"删除物料出错:"+e.getMessage());
}
}
}

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

@@ -17,13 +17,14 @@ import com.example.bpa.db.mode.BPA_MATERIAL;
import com.example.bpa.db.mode.BPA_USER;
import com.example.bpa.helper.T;
import com.example.bpa.view.adapter.wl_adapter;
import com.example.bpa.view.inteface.MyClickListener;

import java.util.ArrayList;

/**
* 物料管理
*/
public class wlgl_activity extends AppCompatActivity implements View.OnClickListener{
public class wlgl_activity extends AppCompatActivity implements View.OnClickListener, MyClickListener {

//region 变量
/**
@@ -98,7 +99,7 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList
{
try{
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);
}catch(Exception e){

@@ -139,5 +140,14 @@ public class wlgl_activity extends AppCompatActivity implements View.OnClickList
break;
}
}

/**
* 接口方法,响应ListView按钮点击事件
*/
@Override
public void clickListener(View v,Object data) {
QueryDB.DeleteMaterial((BPA_MATERIAL)data);
Initdata();
}
//endregion
}

+ 9
- 0
app/src/main/java/com/example/bpa/view/inteface/MyClickListener.java View File

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

+ 43
- 51
app/src/main/res/layout/datatab/layout/wl_item.xml View File

@@ -3,58 +3,50 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/dpbj"
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_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>

+ 4
- 5
app/src/main/res/layout/from/layout/activity_wlgl.xml View File

@@ -165,7 +165,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_alignParentLeft="true"
android:text="回锅肉"
android:text="物料名称"
android:textColor="@color/dataGridColumnHeaderColor"
android:textSize="@dimen/textSize" />
</RelativeLayout>
@@ -194,10 +194,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#00000000"
android:dividerHeight="14dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"/>
android:dividerHeight="3dp"
android:layout_marginTop="3dp"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>


Loading…
Cancel
Save