0
私はにしたいです。一度項目をにしてループで使用します。私は現在解決策を持っていますが、最も良い方法があります。また、view.removeView
コールがないとプログラムは実行されませんが、意味がありますが、後でcatBtn
をアプリに追加したい場合は危険です。複数回使用するスタイルのシングルインフレーション
既存のコード:
LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
for(int i = 0; i < 10; ++i) {
LinearLayout assets = (LinearLayout)this.getLayoutInflater().inflate(R.layout.assets, null);
Button btn = (Button)assets.findViewById(R.id.catBtn);//new Button(this);
assets.removeView(btn);
col1.addView(btn);
}
layout.assets
<?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:weightSum="1"
android:id="@+id/assets">
<ImageView android:focusable="true"
android:id="@+id/thumb"
android:background="@drawable/selectable"
android:layout_marginBottom="20dip"
android:src="@drawable/icon" android:layout_height="140dip" android:layout_width="250dip"/>
<Button android:id="@+id/catBtn"
android:layout_height="wrap_content"
android:background="@drawable/selectable"
android:text="Cat Button"
android:layout_width="120dip"
android:textSize="16dip"></Button>
</LinearLayout>
あなたの例は、すぐには使えませんでしたが、良いスタートに私を得ました。私は残りの部分を(編集として)得たリンクを投稿しましたが、あなたの投稿が90%あったので、あなたは信用を得ると言います。それだけでなく、あなたの答えにリアルタイムを入れて、あなたが行った長さに本当に感謝します。それは確かに+1です。ありがとう! – Jacksonkr
申し訳ありませんが、私はそれをコンパイルしませんでした。あなたが残りの道を行くとうれしい:) –