2016-10-15 5 views
0

私はフラッシュカード形式で表示された各サブジェクトの進行状況を示すために更新する必要がある3つのプログレスバーを持っています。各プログレスバーは個別に進んでください。共有の設定を使用して、フラッシュカードアクティビティの進行状況を保存し、そのデータを進行状況バーを処理するアクティビティに読み込みます。最初のプログレスバーを調整するだけですが、3つのプログレスバーはすべて最初のものと同じに調整されます。1つのプログレスバーを変更するとすべてのプログレスバーが変更されます

私のプログレスバーのXML

<ProgressBar 
    style="?android:attr/progressBarStyleHorizontal" 
    android:id="@+id/introProgress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:max="4" 
    android:progress="0" 
    android:indeterminate="false" 
    android:layout_gravity="center" 
    android:padding="5dp" 
/> 

<ProgressBar 
style="?android:attr/progressBarStyleHorizontal" 
    android:id="@+id/howToStudyProgress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:max="100" 
    android:progress="0" 
    android:indeterminate="false" 
    android:layout_gravity="center" 
    android:padding="5dp" 
/> 

<ProgressBar 
    style="?android:attr/progressBarStyleHorizontal" 
    android:id="@+id/proceduresProgress" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:max="100" 
    android:progress="0" 
    android:indeterminate="false" 
    android:layout_gravity="center" 
    android:padding="5dp" 
/> 

全3つの進捗バーは、ID以外全く同じに見えます。フラッシュカードアクティビティに保存された

データは

private void savePosition(){ 
    SharedPreferences sharedPrefs = this.getActivity().getSharedPreferences("Intro", Context.MODE_PRIVATE); 
    SharedPreferences.Editor editor = sharedPrefs.edit(); 
    editor.putInt("Intro Progress", progress); 
    editor.putInt("Intro Position", position); 
    editor.putBoolean("Viewed State", viewed); 
    editor.commit(); 
} 

は、私は私のプログレスバーの活動に私のフラッシュカードアクティビティから自分のデータをロード

progressBarIntro = (ProgressBar)myView.findViewById(R.id.introProgress); 
progressBarStudy = (ProgressBar)myView.findViewById(R.id.howToStudyProgress); 
progressBarProcedures = (ProgressBar)myView.findViewById(R.id.proceduresProgress); 

私のプログレスバーの活動で私の進捗バーを定義

private void loadPreferences() 
{ 
    SharedPreferences sharedPreferences = this.getActivity().getSharedPreferences("Intro", Context.MODE_PRIVATE); 
    introProgressValue = sharedPreferences.getInt("Intro Progress", 0); 
    introViewed = sharedPreferences.getBoolean("Viewed State", false); 
} 

フラッシュカードから読み込まれたデータに基づいてプログレスバーを設定します。 ITY

private void setupProgressBars(){ 
if(!introViewed){ 
    progressBarIntro.setProgress(0); 
} 
if(introViewed){ 
    progressBarIntro.setProgress(introProgressValue + 1); 
} 
progressBarIntro.setMax(4); 
} 

全.xmlファイルを示す進捗バー(私はこの1と同期して、その進捗状況を変更することが私の他の進捗バーのために見ることができない理由はありませんので、イントロの進行状況バーのみ設定している)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
> 
<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:layout_alignParentTop="true" 
    > 

    <!-- 
    this goes in the above scrollview 
    android:layout_above="@+id/adView" 
    --> 


    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     > 

     <!-- INTRODUCTION --> 
     <LinearLayout 
      android:id="@+id/introView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@drawable/button_no_border_selector" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:onClick="introduction" 
      > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="INTRODUCTION" 
       android:gravity="center" 
       android:padding="5dp" 
       /> 
      <ProgressBar 
       style="?android:attr/progressBarStyleHorizontal" 
       android:id="@+id/introProgress" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="0" 
       android:layout_gravity="center" 
       android:padding="5dp" 
       /> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:weightSum="2" 
       > 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="0/10" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Progress" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="--" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Last Reviewed" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/layoutview_background" 
      /> 

     <!-- HOW TO STUDY --> 
     <LinearLayout 
      android:id="@+id/howToStudyView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@android:drawable/list_selector_background" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:onClick="howToStudy" 
      > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="HOW TO STUDY" 
       android:gravity="center" 
       android:padding="5dp" 
       /> 
      <ProgressBar 
       style="?android:attr/progressBarStyleHorizontal" 
       android:id="@+id/howToStudyProgress" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="0" 
       android:layout_gravity="center" 
       android:padding="5dp" 
       /> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:weightSum="2" 
       > 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="0/10" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Progress" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="--" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Last Reviewed" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/layoutview_background" 
      /> 

     <!-- BOARD PROCEDURES --> 
     <LinearLayout 
      android:id="@+id/boardProceduresView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@android:drawable/list_selector_background" 
      android:paddingBottom="10dp" 
      android:paddingTop="10dp" 
      android:onClick="boardProcedures" 
      > 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="BOARD PROCEDURES" 
       android:gravity="center" 
       android:padding="5dp" 
       /> 
      <ProgressBar 
       style="?android:attr/progressBarStyleHorizontal" 
       android:id="@+id/proceduresProgress" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:max="100" 
       android:progress="0" 
       android:layout_gravity="center" 
       android:padding="5dp" 
       /> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" 
       android:weightSum="2" 
       > 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="0/10" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Progress" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
       <LinearLayout 
        android:layout_width="0dp" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="vertical" 
        > 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="--" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="Last Reviewed" 
         android:gravity="center" 
         android:padding="5dp" 
         /> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/layoutview_background" 
      /> 

    </LinearLayout> 

</ScrollView> 
<!-- ADVIEW GOES HERE--> 

</RelativeLayout> 

私のコードの一部をスキップして謝罪します。私も自分の進捗バー

に描画可能を適用しています
Resources res = getResources(); 
Drawable drawable = res.getDrawable(R.drawable.progress); 

progressBarIntro = (ProgressBar)myView.findViewById(R.id.introProgress); 
progressBarIntro.setProgressDrawable(drawable); 

temp = (ProgressBar)myView.findViewById(R.id.temp); 
temp.setProgressDrawable(drawable); 
+0

に異なる描画可能な追加しますか?また、残りの 'ProgressBar's xmlsもポストしてください。 – Onik

+0

3つのプログレスバーはすべて同じ.xmlファイル内にあり、元のファイルからコピーされましたが、元のファイルにコピーされました。 progressBarIntroを変更するためのコードを書いていないのに、progressBarIntroと同期して3つのプログレスバーがすべて進捗状況を変更しています。 – th3ramr0d

+0

'layout_gravity =" center "属性のためにそれらが重なっていませんか? – Onik

答えて

0

ソリューション:何を変えています各プログレスバー

Resources res = getResources(); 
Drawable drawableIntro = res.getDrawable(R.drawable.progress); 
Drawable drawableTemp = res.getDrawable(R.drawable.progress); 

progressBarIntro = (ProgressBar)myView.findViewById(R.id.introProgress); 
progressBarIntro.setProgressDrawable(drawableIntro); 

temp = (ProgressBar)myView.findViewById(R.id.temp); 
temp.setProgressDrawable(drawableTemp); 
関連する問題