저는 Android 프로그래밍에 익숙하지 않습니다. 특정 Inventory Item을 스캔하고 ArrayList에 이미 존재하는 바코드를 검색하는 기능을 구현 중입니다. 존재하는 경우 현재 조각을 InvNetoryFound Fragment로 대체합니다. 수량을 업데이트하고 ArrayList에서 항목을 완전히 제거 할 수있는 옵션이 있습니다.오래된 데이터가 표시된 부분
스캔 할 때 다른 인벤토리 바코드를 다시 스캔 할 때 Inventory를 제거한 후 ArrayList에서 제거 된 이전 데이터로 InventoryFound Fragment가 표시됩니다.
private static void showFragment(Fragment fragment, String back_option) {
try {
// start transition
FragmentTransaction ft = activity.getFragmentManager().beginTransaction();
//if fragment Inventory is found then pass data to fragment
if(back_option.equals("inventoryFound")){
//sends found inventory list data to fragment
String[] inv_data = inventory_list.get(inventory_index);
Bundle bundle = new Bundle();
bundle.putStringArray("inventory_data",inv_data);
bundle.putInt("inventory_index",inventory_index);
inventoryFoundFragment.setArguments(bundle);
back_option = "null";
// replace fragment
if (!back_option.equals("null")) // with back option
ft.replace(R.id.frag_content, fragment).addToBackStack(back_option);
else // no back option
ft.replace(R.id.frag_content, fragment);
// commit
ft.commit();
}
catch(Exception e){
out("PROBLEM SHOWING FRAGMENT!!!"+e.getMessage());
}
}
InventoryFound 조각 데이터를 채우고 잘 작동 : 스캔이 조각을 대체하기 위해 아래와 같은 기능을 호출에 성공하면
public static String[] inve = new String[5];
public static ArrayList<String[]> inventory_list = new ArrayList<String[]>();
inve[0] = "INV45879";
inve[1] = "Bridge Support Pipe";
inve[2] = "Pre-insulated pipe supports provide both support and insulation in hot and cold piping applications.Pre-insulated pipe supports provide both support and insulation in hot and cold piping applications.";
inve[3] = "0885370720679";
inve[4] = "2";
inventory_list.add(inve);
inve = new String[5];
inve[0] = "INV45880";
inve[1] = "Cement";
inve[2] = "Pre-insulated pipe supports provide both support and insulation in hot and cold piping applications";
inve[3] = "9771234567003";
inve[4] = "8";
inventory_list.add(inve);
:
시험의 ArrayList 코드 : 다음은 내 코드입니다. 다음은 채워진 인벤토리 제거를 클릭하면 표시되는 코드입니다.
public void removeInventory(){
Shared.inventory_list.remove(inventory_index);
Toast.makeText(mContext,"Inventory "+inventory_index+" Removed Successfully!", Toast.LENGTH_SHORT).show();
FragmentTransaction ft = getActivity().getFragmentManager().beginTransaction();
ft.remove(this);
ft.replace(R.id.frag_content, new ScanFragment());
ft.commit();
}
예를 들어 성공적으로 제거했지만 다시 스캔 할 때 예 : 바코드 "0885370720679"의 경우 InventoryFound 조각에 이전 데이터가 표시됩니다. Logcat (Log.d)에서 디버깅했는데 올바른 데이터를 볼 수 있지만 조각에 표시되지 않습니다.
어떤 제안이나 안내도 부탁드립니다.