我的动态创建的小部件不显示我的、部件、动态

由网友(害羞鬼.)分享简介:我的code编译罚款,当我开始活动,就会显示其关联的布局,但小部件动态地在OnCreate之后创建()不显示。为什么不呢?Eclipse不落入调试角度来看,他们根本就不会出现。下面是相关的code:公共类Authorize_Activity_DynamicControls延伸活动{@覆盖公共无效的onCreate(包...

我的code编译罚款,当我开始活动,就会显示其关联的布局,但 小部件动态地在OnCreate之后创建()不显示。

为什么不呢?

Eclipse不落入调试角度来看,他们根本就不会出现。

下面是相关的code:

 公共类Authorize_Activity_DynamicControls延伸活动{

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.ondemandandautomatic_dynamicauthorize);

        的LinearLayout llay =新的LinearLayout(本);
        llay.setOrientation(LinearLayout.HORIZONTAL);

        LinearLayout.LayoutParams LLP =新的LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
        llp.weight = 1.0F;

        复选框CB =新的复选框(getApplicationContext());
        cb.setText(1);
        cb.setLayoutParams(LLP);
        llay.addView(CB);

        滚动型SVH =(滚动型)findViewById(R.id.scrollViewHost);
        svh.addView(llay);
    }
 

...这是布局的xml:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=横向>

        <的TextView
            机器人:ID =@ + ID / textView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =2DIP
            机器人:文本=@字符串/需求
            机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

        <的TextView
            机器人:ID =@ + ID / textView2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =2DIP
            机器人:文本=@字符串/时间
            机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

        <的TextView
            机器人:ID =@ + ID / textView3
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =2DIP
            机器人:文本=@字符串/空间
            机器人:textAppearance =:/>中的Andr​​oid ATTR / textAppearanceSmall?

        <的TextView
            机器人:ID =@ + ID / textView4
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_margin =2DIP
            机器人:文本=@字符串/接触
            机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>

    <滚动型
        机器人:ID =@ + ID / scrollViewHost
        机器人:fillViewport =真
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =match_parent>

    < /滚动型>

< / LinearLayout中>
 
如何在iPhone上创建自定义小部件

解决方案

您应该不需要无效您的onCreate已添加的意见()。如果没有XML布局文件它也有一些猜测,试图自信地回答后。您是否尝试过使用复选框的一个TextView呢?

My code compiles fine, and when I start the Activity, its associated layout is displayed, but the widgets I dynamically create thereafter in the onCreate() do not display.

Why wouldn't they?

Eclipse doesn't drop into the Debug Perspective, they simply don't show up.

Here's the relevant code:

public class Authorize_Activity_DynamicControls extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ondemandandautomatic_dynamicauthorize);

        LinearLayout llay = new LinearLayout(this); 
        llay.setOrientation(LinearLayout.HORIZONTAL); 

        LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT,     
LayoutParams.WRAP_CONTENT); 
        llp.weight = 1.0f; 

        CheckBox cb = new CheckBox(getApplicationContext()); 
        cb.setText("1"); 
        cb.setLayoutParams(llp); 
        llay.addView(cb);

        ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost);
        svh.addView(llay);
    }

...and here's the layout xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >    

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dip"
            android:text="@string/demand"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dip"
            android:text="@string/time"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dip"
            android:text="@string/space"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="2dip"
            android:text="@string/contact"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    <ScrollView
        android:id="@+id/scrollViewHost"
        android:fillViewport="true"
        android:layout_width="wrap_content"
        android:layout_height="match_parent" >

    </ScrollView>

</LinearLayout>

解决方案

You shouldn't need to invalidate the views you've added in onCreate(). Without having the XML layout file it's also some guesswork to try to answer the post confidently. Have you tried using a TextView instead of checkbox?

阅读全文

相关推荐

最新文章