2017-08-02 94 views
0

當前我在Tabbed Activity選項卡中,並且我已在佈局中設置了friends_fragment!我的friends_fragment包含回收站視圖。另一個佈局命名爲activity_friends,它被設置爲viewHolder用於該回收站視圖。我在activity_friends中擁有進度條,並希望通過該選項卡式活動訪問它。我怎麼能做到這一點從另一個佈局進度條,並在另一個佈局中顯示它

@Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, 
           Bundle savedInstanceState) { 
      View view = inflater.inflate(R.layout.fragment_friends, container, false); 


      LayoutInflater factory = LayoutInflater.from(getContext()); 
      DialogView = factory.inflate(R.layout.activity_friends, null); 
      bar=(ProgressBar)DialogView.findViewById(R.id.pBar); 

      bar.setVisibility(DialogView.INVISIBLE); // or VISIBLE 

      return view; 


     } 

Friends_Fragment

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.umairahmed.tracknotesapp.Friends"> 


    <android.support.v7.widget.RecyclerView 

     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/friendRecyclerView" 
     > 

    </android.support.v7.widget.RecyclerView> 


</RelativeLayout> 

Activity_friends

<ProgressBar 
    style="?android:attr/progressBarStyle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="14dp" 
    android:layout_marginEnd="14dp" 
    android:id="@+id/pBar" 
    android:layout_centerVertical="true" 
    android:layout_alignRight="@+id/userImg" 
    android:layout_alignEnd="@+id/userImg" /> 

回答

0

更新fragment_activity佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.umairahmed.tracknotesapp.Friends"> 

<FrameLayout 
    android:id="@+id/MainFrame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/friendRecyclerView"> 

      </android.support.v7.widget.RecyclerView> 

    </FrameLayout> 
</RelativeLayout> 

和Fragment_activity Java類

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_friends, container, false); 


     FrameLayout MainFrame = (MainFrame)view.findViewById(R.id.MainFrame); 
     LayoutInflater factory = LayoutInflater.from(getContext()); 
     DialogView = factory.inflate(R.layout.activity_friends, null); 
     MainFrame.addView(DialogView); 

     bar=(ProgressBar)DialogView.findViewById(R.id.pBar); 

     bar.setVisibility(DialogView.INVISIBLE); // or VISIBLE 

     return view; 


    } 
+0

它說我要添加限定符或方法,它不允許我在視圖中使用addView() –

+0

我更新了我的答案@UmairAhmed –

相關問題