2016-10-31 4 views
2

PanelActivity에는 항목 목록이있는 recyclerView가 있습니다. 각 항목에는 클릭 이벤트가 있습니다. 이 클릭은 DetailsActivity을 엽니 다.대화 상자가 닫히면 작업 완료

DetailsActivity에는 전체 화면 대화 상자 (내 클래스 DetailDialogFragmentDialogFragment)를 여는 floatingActionButton이 있습니다.

DetailDialogFragment에는 해제 버튼이 있습니다.

문제 : 사용자가 위로 버튼을 클릭하면 대화 상자가 닫히고 DetailsActivity도 사라지고 앱이 PanelActivity으로 돌아갑니다.

가능한 이유 : 대화 상자의 위로 단추 아래에 DetailsActivity의 위로 단추가 있습니다. 대화 상자가 액티비티 위에 있고 둘 다 같은 위치에 위로 버튼이있을 때 두 번의 클릭 이벤트를 실행할 수 있습니까?


편집 : 일부 코드를 표시합니다.

열기 세부 정보 PanelActivity의 활동 (recyclerView에서 항목 하나를 클릭).

Intent intent = new Intent(context, DetailsActivity.class); 
intent.putExtra("headerCode", headerCode.getText()); 
context.startActivity(intent); 

DetailsActivity의 위쪽 버튼.

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     // Respond to the action bar's Up/Home button 
     case android.R.id.home: 
      NavUtils.navigateUpFromSameTask(this); 
      return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 

DetailsActivity에서 전체 화면 대화 상자를 엽니 다.

private void showCreateDetailDialog() { 
    FragmentManager fragmentManager = getSupportFragmentManager(); 
    DetailDialogFragment newFragment = new DetailDialogFragment(); 

    // The device is smaller, so show the fragment fullscreen 
    FragmentTransaction transaction = fragmentManager.beginTransaction(); 
    // For a little polish, specify a transition animation 
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
    // To make it fullscreen, use the 'content' root view as the container 
    // for the fragment, which is always the root view for the activity 
    transaction.add(android.R.id.content, newFragment) 
      .addToBackStack(null).commit(); 
} 

마지막으로 DetailDialogFragment의 위로 버튼.

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 

    if (id == R.id.save) { 
     validateForm(); 
     return true; 
    } else if (id == android.R.id.home) { 
     // handle close button click here 
     dismiss(); 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
+0

일부 소스 코드 – Krish

+0

@Krish 내 게시물을 편집했습니다. – JCarlos

답변

0

아니요, 가능하지 않습니다. 기기의 문제 일 수 있습니다. Android 에뮬레이터 또는 다른 기기에서 테스트 해보세요. 코드를 공유하여 도움을받을 수 있습니까?

+0

다시 확인하십시오. 그리고 그것은 에뮬레이터에서도 발생합니다. – JCarlos

1

필자는 테스트하지 않았지만 문제는 여기에서 dismiss()를 호출하는 곳이라고 생각합니다. 먼저 DialogFragment에 대한 참조가 필요할 수 있습니다. 난 그냥 당신이에서 작업 활동에 해당 this.dismiss();를 호출하고 기술적으로 생각

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 

    if (id == R.id.save) { 
     validateForm(); 
     return true; 
    } else if (id == android.R.id.home) { 
     // handle close button click here 
     dismiss(); // problem is with this call 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

당신은이 같은 시도 할 수 있습니다 :. onOptionsItemSelected() 안에 지금

private DetailDialogFragment detailFragment; 

private void showCreateDetailDialog() { 
    detailFragment = new DetailDialogFragment(); 
    FragmentManager fragmentManager = getSupportFragmentManager(); 

    FragmentTransaction transaction = fragmentManager.beginTransaction(); 
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
    transaction.add(android.R.id.content, newFragment).addToBackStack(null).commit(); 
} 

과 :

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    int id = item.getItemId(); 

    if (id == R.id.save) { 
     validateForm(); 
     return true; 
    } else if (id == android.R.id.home) { 
     // handle close button click here 
     detailFragment.dismiss(); 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 
+0

도움 주셔서 감사합니다. 그러나,''detailFragment''' 속성은 액티비티에 정의되어 있고, 프래그먼트는 다른 클래스입니다. – JCarlos

관련 문제