android – 将循环进度条用作alertdialog或progressdialog

我正在使用这个库为我的
android服装创建一个循环进度条(
https://github.com/lzyzsd/CircleProgress).

我创建了一个布局,其中定义了循环进度条.

 <?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或progress对话框弹出.我能够做到这一点.这是代码.

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

请帮忙做什么.

最佳答案 你已经设置了setContentView(R.layout.pogress_bar);在显示对话框后你必须在执行findViewById之前在onCreate()中设置它

点赞