2017-02-22 5 views
0

도움이 필요합니다. 앱을 개발 중입니다.onItemClick FirstFragment로 이동하는 경우 elseFragment로 이동

내 탐색 모음입니다. 세 가지 옵션 메뉴 (색깔있는 메뉴)가 있습니다.

1) 세 번째 조각을)
2) 3
을 MapFragment가

Image Here

을 FirstFragment 그리고 이것은 내 탐색 서랍 "설립 유형 목록"으로 구성되어있다.

클릭하면 설치 목록으로 구성된 다른 조각 (ListFragment)이 열립니다. 기능은 FirstFragment에 그렇지 않으면 MapFragment가 이동에

list

사업체는 것이다.

시나리오 : 사용자가 은행에가 있는지 확인합니다를 클릭 할 때

1) 내가 에있어 경우 FirstFragment-> 탐색을 클릭 drawer->이 시나리오> 은행

을 ListFragment-을 클릭 사용자가 FirstFragment에 있으면 FirstFragment로 진행합니다. 그렇지 않으면 MapFragment ........로 이동합니다. 결과는 FirstFragment로 이동합니다.

2) 내가 MapFragment-에있어 경우> drawer-> 사용자가 그렇지는 MapFragment가로 이동합니다 FirstFragment에있는 경우 그것은 확인> 은행

을 ListFragment-을 클릭 탐색을 클릭합니다 ..... ...... 결과는 MapFragment로 이동합니다.

문제 : 그래서 난 내 코드에 그것을 구현하는 방법을 모른다되어이 문제 ... 내 MainActivity에서 여기

코드 :

@Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     android.app.FragmentManager fragmentManager = getFragmentManager(); 

     if (id == R.id.action_ar) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new FirstFragment()) 
        .commit(); 
      Toast.makeText(this, "First Selected", Toast.LENGTH_SHORT).show(); 
     } 
     else if (id == R.id.action_map) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new MapFragment()) 
        .commit(); 
      Toast.makeText(this, "MAP Selected", Toast.LENGTH_SHORT).show(); 
     } 
     else if (id == R.id.action_direction) { 
      fragmentManager.beginTransaction() 
        .replace(R.id.content_frame, new ThirdFragment()) 
        .commit(); 
      Toast.makeText(this, "Third Selected", Toast.LENGTH_SHORT).show(); 
     } 
     return super.onOptionsItemSelected(item); 
    } 
+0

귀하의 문제는'FirstFragment'에 존재하는, 당신이 그 코드를 표시해야하므로이 예제 코드를 사용 할 일에 대한 ... –

+0

문제는 어떻게해야할지 모르겠다. 그래서 제가 도움이 필요합니다. – Problematic

+0

더 많은 코드로 질문을 편집 해주십시오. 질문이 명확하지 않은 것 같습니다. –

답변

-1

당신은 통과 할 수 변수 "from_where_did_icome"(예 : 조각)으로 갈 때마다 또는 다른 곳으로 가면 어디에서 왔는지 확인하십시오.

//Passing data to fragment: 

Bundle bun = new Bundle(); 
bun.putString("pathimage", path); 
fragment_setting.setArguments(bun); 

//Getting data in fragment: 

Bundle b = getArguments(); 
String path = b.getString("pathimage"); 

이 두 개의 링크에서 자세히 알아보기 : https://developer.android.com/training/basics/fragments/communicating.htmlhttps://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity

+0

[mcve]를 만들어보십시오. 현재 사용중인 조각을 알려주기 위해 추가 변수가 필요한 이유는 무엇입니까? PHP처럼 밑줄 친 변수 이름을 사용하는 이유는 무엇입니까? –

+0

@Nick 그것은 당신이 어디에서 왔는가가 아니라 어떤 조각/활동에서 왔는지, 그 정보로 우리는 그가 단순한 if 또는 switch 후에 무엇을 물을 수 있는지 결정할 수 있습니다. 또한 답변도 편집했습니다. –