0

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

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

我该怎么做呢?

另外我知道,当我们通过 Inflater 创建一个新视图时,我们需要通过 addContentView() 将其添加到当前活动类中,尽管到目前为止我已经尝试了很多,但我不知道该怎么做。

有人可以在这里帮助我吗?

4

1 回答 1

3

所以,既然你不提供代码,让我搜索我的水晶球……等等……好吧,就是这样。你有这样的事情:

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( LinearLayout,RelativeLayout等;我的水晶球看不清楚)。然后,您需要为该容器设置一个 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);
于 2010-12-02T13:53:18.980 回答