2014-09-17 5 views
0

저는 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)에서 디버깅했는데 올바른 데이터를 볼 수 있지만 조각에 표시되지 않습니다.

어떤 제안이나 안내도 부탁드립니다.

답변

0

이 문제에 대한 해결책을 찾았습니다.

Fragment가 포 그라운드 인 경우 onResume() 메서드를 호출합니다. 이 방법에서는 Fragment 필드에 대한 데이터를 다시 설정하는 사용자 정의 함수를 호출합니다. 이 문제를 해결하는 것이 올바른지는 모르겠지만 지금은 저에게 맞습니다!

관련 문제