【问题标题】:to use circular progress bar as alertdialog or progressdialog使用循环进度条作为 alertdialog 或 progressdialog
【发布时间】:2016-06-24 04:02:31
【问题描述】:

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

所以圆形进度条显示为警报对话框。现在我想设置进度,因为它通过代码。谁能指导我如何在库代码中执行此设置进度功能。

应该有类似的方式

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

请帮忙怎么办。

【问题讨论】:

  • 天哪。起什么名字。很难阅读。检查android的命名约定

标签: android wear-os progressdialog


【解决方案1】:

你已经设置setContentView(R.layout.pogress_bar);在对话框显示之后你必须在 onCreate() 中设置它,然后再执行 findViewById

【讨论】:

  • 但是如何随着代码的进行更改 setprogress 值。因为我不能每次都调用 onCreate 对
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-02
  • 2018-01-30
  • 2013-10-15
  • 1970-01-01
相关资源
最近更新 更多