我正在使用这个库为我的 android wear ( 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>
我希望这个定义了循环进度条的布局以警报对话框或进度对话框的形式弹出。我能够做到这一点。这是相关代码。
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() 中设置它
关于android - 使用循环进度条作为 alertdialog 或 progressdialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38005409/