我想要更新的进展吧在我的应用程序。

我已经创建了一个新的视图通过使用环节,并在新创建的看法我想显示水平的进展吧更新。

我怎么可以做的,特别是?

我也得知道,当我们创造一个新的视图通过环节,我们需要将它添加到目前的活动类addContentView(),我不知道如何做到这些,虽然我尝试了很多,直到现在。

任何人可以帮助我这里吗?

有帮助吗?

解决方案

所以,你没有提供代码,让我搜寻我的晶球...等等...OK,那里它是。你有什么事情是这样的:

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top