2013-08-28 7 views
0

표시되지 않는 TextView를 동적으로 추가하고 있는데 문제가있는 것 같습니까?동적으로 추가 할 때 TextView가 표시되지 않습니다.

다음 두 줄 사이에 차이가 있습니다 :

receiptLayout.addView(order_1_confirm); 

((LinearLayout) receiptLayout).addView(order_1_confirm); 

글쎄, 어느 쪽도 그들 중 하나가 작동하지 않습니다!

내 activity_receipt.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/receiptMainLinearLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/image_view_rsc_logo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/rsc_logo" 
    android:src="@drawable/rsc" /> 

내 ReceiptActivity.java :

public class ReceiptActivity extends Activity{ 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_receipt); 

    LinearLayout receiptLayout = (LinearLayout)findViewById(R.id.receiptMainLinearLayout); 
    TextView order_1_confirm = new TextView(this); 
    order_1_confirm.setText("hello"); 

      //receiptLayout.addView(order_1_confirm); 
    ((LinearLayout) receiptLayout).addView(order_1_confirm); 

} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

}

답변

0

은 그냥 LinearLayoutandroid:orientation="vertical"을 제공합니다.

그리고

LinearLayout receiptLayout = (`LinearLayout`)findViewById(R.id.receiptMainLinearLayout); 

에서

당신은 이미 필요 다시

+0

덕분에 지금은 내 veiws을 볼 수 있습니다 .. – PaulPolon

0

크기와 TextView의 색상을 설정 캐스팅 없음의 LinearLayout에보기를 캐스팅. 아마도 그것은 배경과 같은 색이기 때문에 보이지 않는 것처럼 보일 것입니다.

0

항상 LinearLayout에 방향을 추가해야하며 android:orientation="vertical"을 추가하면 정상적으로 작동합니다.

+0

고맙습니다. – PaulPolon

관련 문제