java使用scrollview将一个xml布局添加到另一个xml中
我是安卓世界的新手。我有一个xml布局,我想作为子项添加到其他xml文件的滚动视图中
这是需要多次插入的布局[offerview.xml]-
必须插入的xml[activity_offer.xml]是-
活动的Java代码是-
public class OfferActivity extends Activity {
private static final String name = "Reebok";
private static final String content = "50% off on Reebok Shoes at Reliance Mart";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offer);
View v = LayoutInflater.from(getApplicationContext()).inflate(R.layout.offerview, null);
TextView offerItemTextView = (TextView) v.findViewById(R.id.offerItemTextView);
offerItemTextView.setText(name);
TextView offerContentTextView = (TextView) v.findViewById(R.id.offertextView);
offerContentTextView.setText(content);
ImageView offerImage = (ImageView) v.findViewById(R.id.offerImageView);
offerImage.setBackgroundResource(R.drawable.ps);
((LinearLayout) findViewById(R.id.offersLayout)).addView(v);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.offer, menu);
return true;
}
}
此时此刻,我只是试图只包含一次视图。应用程序崩溃了
我一直被困在这个问题上
共 (0) 个答案