【问题标题】:Updating the Progress Bar achieved in the New View更新在新视图中实现的进度条
【发布时间】:2010-12-02 13:41:56
【问题描述】:

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

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

我该怎么做?

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

有人可以帮我吗?

【问题讨论】:

    标签: android progress-bar android-inflate


    【解决方案1】:

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

    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 的布局;该布局包含ViewGroupLinearLayoutRelativeLayout 等;我的水晶球看不清楚)。然后,您需要为该容器设置一个 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);
    

    【讨论】:

    • 抱歉没有发布我的代码,非常感谢你的回答(我真的相信你现在可能有一个水晶球,因为我的代码和你显示的一样),你能告诉我在哪里我应该写这行:“LinearLayout mainContainer = (LinearLayout)findViewById(R.id.id_you_gave_to_container);”因为实际上我在扩展 BaseAdapter 的类中的按钮的 Click 事件中执行我的代码。再次感谢克里斯蒂安。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2013-03-08
    • 2020-11-05
    • 2014-04-09
    相关资源
    最近更新 更多