更新新视图中实现的进度条

发布于 2024-10-05 19:57:48 字数 215 浏览 2 评论 0原文

我想更新我的应用程序中的进度栏​​。

我通过使用充气器创建了一个新视图,在该新创建的视图中我想显示水平进度条更新。

我怎样才能特别做到这一点?

我还知道,当我们通过 Inflater 创建一个新视图时,我们需要通过 addContentView() 将其添加到当前活动类中,尽管到目前为止我已经尝试了很多,但我不知道如何执行这些操作。

有人可以帮我吗?

I want to Update the Progress bar in my application.

I have created a new view by making use of inflater and in that newly created view I want to show the Horizontal Progress Bar Updating.

How can I do that particularly?

Also I got to know that when We create a new view by Inflater, we need to add it to the Current Activity Class by addContentView(), I don't know how to do these though I have tried a lot till now.

Can anybody help me here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明媚殇 2024-10-12 19:57:48

因此,由于您不提供代码,所以让我搜索我的水晶球...等等...好吧,就在那里。您有这样的事情:

View someView = inflater.inflate(R.layout.view_with_progress_bar, null);

为了访问您的 ProgressBar,您必须使用 findViewById 方法:

ProgressBar yourProgressBar = (ProgressBar)someView.findViewById(R.id.id_of_your_progress_bar);
// you can know modify the progress bar: yourProgressBar.setBlahBlah

为了将包含进度条的视图添加到您当前的活动中,您必须拥有对之前设置的容器的引用。所以,我猜你之前做过:setContentView(R.layout.something);,然后你就有了一个名为 something.xml; 的布局。该布局包含一个 ViewGroup(LinearLayoutRelativeLayout 等;我的水晶球看不清楚)。然后,您需要为该容器设置一个 ID,创建一个引用,并将新创建的视图添加到其中:

// in your onCreate method
setContentView(R.layout.something);

// let's suppose it's a LinearLayout
LinearLayout mainContainer = (LinearLayout)findViewById(R.id.id_you_gave_to_container);

// blha blah... the rest of your code. Keep in mind that you will
// probably have to declare the mainContainer outside the onCreate method

// here, you have already inflated your view, and want to add it to your activity
mainContainer.addView(someView);

So, as you don't provide code, let me search my crystal ball... wait... OK, there it is. You have something like this:

View someView = inflater.inflate(R.layout.view_with_progress_bar, null);

In order to access your ProgressBar, you have to use the findViewById method:

ProgressBar yourProgressBar = (ProgressBar)someView.findViewById(R.id.id_of_your_progress_bar);
// you can know modify the progress bar: yourProgressBar.setBlahBlah

In order to add the view that contains the progress bar to you current activity, you have to have a reference to the container that you previously set. So, I guess you previously did: setContentView(R.layout.something);, then you have a layout called something.xml; that layout contains a ViewGroup (LinearLayout, RelativeLayout, etc.; my crystal ball can't see that clearly). Then, you need to set an ID to that container, create a reference, and add your newly created view to it:

// in your onCreate method
setContentView(R.layout.something);

// let's suppose it's a LinearLayout
LinearLayout mainContainer = (LinearLayout)findViewById(R.id.id_you_gave_to_container);

// blha blah... the rest of your code. Keep in mind that you will
// probably have to declare the mainContainer outside the onCreate method

// here, you have already inflated your view, and want to add it to your activity
mainContainer.addView(someView);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文