android - 使用循环进度条作为 alertdialog 或 progressdialog

标签 android wear-os progressdialog

我正在使用这个库为我的 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/

相关文章:

android - 可穿戴设备未安装应用程序(Android Wear 功能标准)

android - 在 android wear Action 中更改语音识别器的语言

android - 将计时器与 ProgressDialog 一起使用

android - 从自定义对话框显示进度对话框

android - 我的 Android 应用程序如何在多种屏幕分辨率的设备上运行?

java - 使用 GSON 序列化时出现 "declares multiple JSON fields named"错误

android - 具有不同上下文的共享偏好

wear-os - 唯一标识Android Wear设备

android - ProgressDialog 中的 'indeterminate' 是什么意思?

java - 将自定义 header 添加到 WebView 资源请求 - android