ProgressBar在动态片段中

时间:2014-04-28 13:52:31

标签: android android-layout android-fragments progress-bar

我有布局,取决于屏幕大小显示一个片段,或两个窗格布局。在某些活动中,我在列表视图上方放置了一个进度条(一个微调器)并以编程方式显示/隐藏它,但我无法在我的碎片中实现它。

这是我的工作布局XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingLeft="8dp"
         android:paddingRight="8dp"
         android:gravity="center_horizontal">

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ListView android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

</LinearLayout>

我使用一组方法来显示/隐藏它:

mProgBar = (ProgressBar)findViewById(R.id.progressBar1);    
mProgBar.setVisibility(View.INVISIBLE);
mProgBar.setVisibility(View.GONE);
setListAdapter(projectsAdapter);
getListView().setVisibility(View.VISIBLE);

有了这个,每个人都可以正常工作,但是当我尝试在我的候选人片段中做类似的事情时,进度条没有显示。

SinglePane布局(part_1):

<?xml version="1.0" encoding="utf-8"?>
<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/candidate_list"
    class="com.es.empSystem.candidates.CandidatesListFrag"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    tools:context="com.es.empSystem.projects.candidates.CandidatesList" />

SinglePane布局(第2部分):

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/candidate_detail_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.es.empSystem.candidates.CandidateDetail"
    tools:ignore="MargeRootFrame" />

TwoPane布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:baselineAligned="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:orientation="horizontal"
    android:showDividers="middle"
    tools:context="com.es.empSystem.candidates.CandidatesList" >

    <fragment
        android:id="@+id/candidate_list"
        class="com.es.empSystem.candidates.CandidatesListFrag"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        android:layout_weight="1" />


    <FrameLayout
        android:id="@+id/candidate_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        tools:context="com.es.empSystem.candidates.CandidateDetail" />

</LinearLayout>

FragmentActivity#onCreate加载特定片段:

@Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        intent = getIntent();
        recType = getIntent().getStringExtra("recType");
        ActionBar ab = getActionBar();
        ab.setSubtitle(SharedVariables.getPolishRecruitment(recType));
        if ( (savedInstanceState != null) && (savedInstanceState.containsKey(CandidateDetailFrag.ARG_APPS)) ) {
            applications = savedInstanceState.getParcelableArrayList(CandidateDetailFrag.ARG_APPS);
            pagesCount = savedInstanceState.getInt("pagesCount", 0);
            setPage(savedInstanceState.getInt("page", 1));
            intent.putParcelableArrayListExtra(CandidateDetailFrag.ARG_APPS, applications);
            intent.putExtra("pagesCount", pagesCount);
            intent.putExtra("page", getPage());
            intent.putExtra("recType", recType);
            setContentView(R.layout.act_candidate_list);        
            if (findViewById(R.id.candidate_detail_container) != null){
                mTwoPane = true;
                ((CandidatesListFrag)getSupportFragmentManager().findFragmentById(R.id.candidate_list)).setActivateOnItemClick(true);
            }
        } else {
            String userSID = getUserSID();
            if ( (userSID != null) && (userSID.length() > 0)) {
                Bundle args = getIntent().getExtras();
                jobID = args.getInt("jobID");
                int page = args.getInt("page");
                Toast.makeText(
                        getApplicationContext(),
                        "Aktualizowanie danych...",
                        Toast.LENGTH_SHORT)
                    .show();
                Intent receiveApplicationsIntent = new Intent(CandidatesList.this, ISVCCandidatesRequest.class);
                receiveApplicationsIntent.putExtra("jobID", Integer.toString(jobID));
                receiveApplicationsIntent.putExtra("userSID", userSID);
                receiveApplicationsIntent.putExtra("page", Integer.toString(page));
                receiveApplicationsIntent.putExtra("recType", recType);
                startService(receiveApplicationsIntent);
            } else {
                startActivity(new Intent(getApplicationContext(), EsLogin.class));
            }
        }
    }

是否有某种方法可以将这样的进度条添加到这些片段中(我只需要在列表片段上方,在两个窗格布局中显示时不需要在两个片段之上)?

0 个答案:

没有答案