我正在开发一款应用。当用户添加项目时,此适配器将表单添加到视图中。用户可以更改表单中的数据以修改相应的项目。
但是,当有多个项目时,会出现以下问题: 我写任何形式的东西 2.滚动视图(屏幕)以查看另一个表单 3.我刚刚放入的数据被随机移动到另一种形式
以下是代码,感谢您的任何建议。
package com.************.fragments;
//imported some Android libraries (omitted due to length limit)
/*
imported some classes from com.******** (omitted due to length limit)
*/
public class MaintenanceRecordFragment extends Fragment implements Saveable {
//view adapter
public class MaintenanceRecordAdapter extends ArrayAdapter<Sychronizable.RemovableItem> {
List<Sychronizable.RemovableItem> lineItemList;
Context context;
LineItem.Record lineItemRecord;
EditText DGINo;
public MaintenanceRecordAdapter(Context context, List<Sychronizable.RemovableItem> lineItemList) {
super(context, -1, lineItemList);
int itemSize = lineItemList.size();
this.lineItemList = lineItemList;
this.context = context;
}
@Override
public View getView(final int pos, final View convertView, ViewGroup parent) {
final View layout = (convertView == null) ? ((LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.maintenance_item, parent, false) :
convertView;
lineItemRecord = (LineItem.Record) getItem(pos);
final Asset.Record assetRecord = asset.findAssetByAssetId(lineItemRecord.assetId);
CheckBox gpaReport = (CheckBox) layout.findViewById(R.id.maintenance_GPA_report);
View completed = layout.findViewById(R.id.maintenance_complete);
TextView capOff = (TextView) layout.findViewById(R.id.maintenance_cap_off);
final TextView symptom = (TextView) layout.findViewById(R.id.maintenance_sympton);
TextView connection = (TextView) layout.findViewById(R.id.maintenance_connection);
TextView model = (TextView) layout.findViewById(R.id.maintenance_model);
final EditText DGIType = (EditText) layout.findViewById(R.id.maintenance_DGI_type);
DGINo = (EditText) layout.findViewById(R.id.maintenance_DGI_number);
final TextView expiryDate = (TextView) layout.findViewById(R.id.maintenance_hose_expiry_date);
TextView brokenCause = (TextView) layout.findViewById(R.id.maintenance_broken_cause);
TextView replaceHose = (TextView) layout.findViewById(R.id.maintenance_refuse_replace_hose);
TextView solution = (TextView) layout.findViewById(R.id.maintenance_solution);
TextView serial = (TextView) layout.findViewById(R.id.maintenance_serial);
TextView qrScanner = (TextView) layout.findViewById(R.id.maintenance_serial_qrcode_scanner);
//allow editing "remarks" field
final EditText remarks = (EditText) layout.findViewById(R.id.maintenance_note);
final TextView checkSeries = (TextView) layout.findViewById(R.id.maintenance_check_series);
checkSeries.setHint(getString(R.string.norecord));
final CheckBox noNeedAssess = (CheckBox) layout.findViewById(R.id.maintenance_no_need_no_access);
//edit existing record
MenuFactory.PopupMenuListener listener = new MenuFactory.PopupMenuListener() {
@Override
public void onPopupMenuEnter(View view, View container) {
String value = ((TextView) container).getText().toString();
lineItemRecord.modify();
switch (container.getId()) {
case R.id.maintenance_sympton:
lineItemRecord.symptom = value;
break;
case R.id.maintenance_connection:
if (assetRecord != null) assetRecord.connection = value;
break;
case R.id.maintenance_model:
if (assetRecord != null) assetRecord.model = value;
break;
case R.id.maintenance_DGI_number:
lineItemRecord.DGINo = value;
break;
case R.id.maintenance_DGI_type:
lineItemRecord.DGIType = value;
break;
case R.id.maintenance_hose_expiry_date:
if (assetRecord != null) assetRecord.hoseExpiryDate = value;
break;
case R.id.maintenance_broken_cause:
lineItemRecord.brokenCause = value;
break;
case R.id.maintenance_refuse_replace_hose:
lineItemRecord.refuseReplaceHose = value;
break;
case R.id.maintenance_solution:
lineItemRecord.solution = value;
break;
case R.id.maintenance_cap_off:
lineItemRecord.capOff = value;
break;
case R.id.maintenance_note:
lineItemRecord.remarks = value;
break;
}
((TextView) container).setText(value);
}
};
if(assetRecord != null && assetRecord.model != null) {
String modelD = assetRecord.model;
String appli = assetRecord.applianceCode;
Log.d("assetTitle1",assetRecord.model);
Log.d("hose expiry","hose expiry: "+assetRecord.hoseExpiryDate);
}
((TextView) layout.findViewById(R.id.maintenance_no)).setText(Integer.toString(pos + 1) + (assetRecord == null ? "" : " - " + assetRecord.model + "," + assetRecord.applianceCode));
symptom.setText(lineItemRecord.symptom);
if (assetRecord != null) connection.setText(assetRecord.connection);
else connection.setText(null);
DGIType.setText(lineItemRecord.DGIType);
if (assetRecord != null) model.setText(assetRecord.model);
else model.setText(null);
String dgino = lineItemRecord.DGINo;
DGINo.setText(lineItemRecord.DGINo);
brokenCause.setText(lineItemRecord.brokenCause);
capOff.setText(lineItemRecord.capOff);
replaceHose.setText(lineItemRecord.refuseReplaceHose);
solution.setText(lineItemRecord.solution);
if (assetRecord != null) serial.setText(assetRecord.serial);
else serial.setText(null);
gpaReport.setChecked(lineItemRecord.gpaReport);
remarks.setText(lineItemRecord.remarks);
//inspecting bug by checking data in a form
Log.d("2.3","2.3 position (+ data): "+pos+"; symptom: "+lineItemRecord.symptom+ "; DGI no.:"+dgino+"; completed: "+lineItemRecord.completed);
//omitted
return layout;
}
public void lockAllView(View view, boolean lock) {
if (view instanceof ViewGroup) {
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++)
lockAllView(((ViewGroup) view).getChildAt(i), lock);
} else {
if (view.getId() != R.id.maintenance_complete) {
view.setEnabled(!lock);
view.setClickable(!lock);
}
}
}
}
//omitted
public static final int SCAN_QRCODE = 0;
Button addRecord;
ListView recordsView;
MaintenanceRecordAdapter adapter;
ChooseAssetAdapter chooseAssetAdapter;
List<Sychronizable.RemovableItem> assetRecordWithoutLineItem = new ArrayList<>();
View wrapper;
LineItem lineItem;
Asset asset;
String orderNo;
Asset.Record qrReturnAsset;
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
orderNo = ((OrderInfoActivity) getActivity()).getOrderNo();
// MaintenanceHome data = ((OrderInfoActivity) getActivity()).getData();
lineItem = ((OrderInfoActivity) getActivity()).getData().getLineItem();
asset = ((OrderInfoActivity) getActivity()).getData().getAsset();
//getAllLineItem();
wrapper = inflater.inflate(R.layout.maintenance_layout, container, false);
filterAssetWithLineItem(asset, lineItem);
chooseAssetAdapter = new ChooseAssetAdapter(getActivity(), assetRecordWithoutLineItem);
if(adapter != null) {
Log.d("originAdapter", String.valueOf(adapter));
}
adapter = new MaintenanceRecordAdapter(getActivity(), lineItem.getRecords());
recordsView = (ListView) wrapper.findViewById(R.id.order_info_stove_repair_list);
recordsView.setAdapter(adapter);
addNewRecords();
/*if the first is empty, remove the first empty value of the lineItem*/
if(lineItem.getRecords().size() > 0) {
Sychronizable.RemovableItem firstItem = lineItem.getRecords().get(0);
LineItem.Record lineItemRecord = (LineItem.Record) lineItem.getRecords().get(0);
if(lineItemRecord.assetId != null) {
Log.d("whatsFirstItem", String.valueOf(lineItemRecord.assetId));
}
else {
lineItem.getRecords().remove(0);
}
}
App.catalogNeedRefresh = true;
if (App.isReadonly)
App.lockAllView(wrapper);
return wrapper;
}
@Override
public void onResume() {
super.onResume();
filterAssetWithLineItem(asset, lineItem);
adapter.notifyDataSetChanged();
}
public List<Sychronizable.RemovableItem> filterAssetWithLineItem(Asset asset, LineItem lineItem) {
assetRecordWithoutLineItem.clear();
for (Sychronizable.RemovableItem removableItem : asset.getAllActiveRecord()) {
Asset.Record assetRecord = (Asset.Record) removableItem;
boolean exist = false;
for (Sychronizable.RemovableItem removableItem2 : lineItem) {
LineItem.Record lineItemRecord = (LineItem.Record) removableItem2;
if (lineItemRecord != null && assetRecord != null && Utility.compStr(lineItemRecord.assetId, assetRecord.assetId)) {
exist = true;
break;
}
}
if (!exist && assetRecord != null)
assetRecordWithoutLineItem.add(assetRecord);
}
return assetRecordWithoutLineItem;
}
//omitted
}
编辑:5月7日下午4:47(GMT + 8)
最后,我找到了防止表单数据意外更改的方法,如下所示:
final LineItem.Record lineItemRecord = (LineItem.Record) getItem(pos);
,似乎因为最终可以防止进一步改变观点(请告诉我,如果我错了,因为我只是初中:))