2016-06-24 16 views
4

我正在使用此庫爲我的android穿戴(https://github.com/lzyzsd/CircleProgress)創建一個圓形進度條。 我已經創建了一個定義圓形進度條的佈局。使用圓形進度條作爲alertdialog或progressdialog

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:background="#000000" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

    android:id = "@+id/progress_layout_id"> 
    <com.github.lzyzsd.circleprogress.ArcProgress 
     android:id="@+id/m_arc_progress" 
     android:layout_width="214dp" 
     android:layout_height="match_parent" 
    /> 

</LinearLayout> 

我想要這個佈局,其中圓形Progressbar被定義爲作爲alertdialog或進度對話框彈出。我能夠做到這一點。這是代碼。

public class progressbar_fragment extends AlertDialog { 
    ArcProgress m_arc; 
    View v; 
    int mProgressVal; 
    Context mContext; 

    protected progressbar_fragment(Context context) { 
    super(context); 
    mContext = context; 
} 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    m_arc = (ArcProgress) findViewById(R.id.m_arc_progress); 


    if (mProgressVal > 0) { 
     setProgress(mProgressVal); 
    } 
} 

@Override 
public void show() { 
    super.show(); 
    setContentView(R.layout.pogress_bar); 
} 

而且我的類文件中調用它作爲

m_arc = new progressbar_fragment(m_caller_context); 
    m_arc.show(); 

所以圓形進度顯示爲alertdialog。現在我想通過代碼來設置進度。任何人都可以請指導我如何做到這一點設置進度函數是否存在庫代碼中。

應該有一些辦法像

m_arc_progress = (ArcProgress) l_progress_layout.findViewById(R.id.m_arc_progress); 
    m_arc_progress.setProgress(0); 

有時它只是適用於初始情況下,當我嘗試做

m_arc_progress.setProgress(25); 

它顯示了我錯誤

> java.lang.NullPointerException: Attempt to invoke virtual method 
> 'android.view.View android.view.Window.findViewById(int)' on a null 
> object reference 

請幫助做什麼。

+0

OMG之前。什麼與命名。這很難閱讀。檢查命名約定爲android – thealeksandr

回答

1

您已設置setContentView(R.layout.pogress_bar);所示的對話框後,你必須設置它的onCreate(),你做一個findViewById

+0

但仍然如何隨代碼進度更改setprogress值。因爲我不能每次都打電話給對方 – MJ123