我有mainactivity
和gridimageactivity
我注意到gridimageactivity正在膨脹的主要活動佈局。我想在R.main_activity中添加新的按鈕和事物。如何解決通貨膨脹另一個R.layout
這是主要活動,因爲你注意到我評論了佈局,但該應用程序仍然顯示textviews和圖像。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
// list = (ListView) findViewById(R.id.list);
Listitem = new ArrayList<Listitem>();
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
GetDataJSON gj = new GetDataJSON();
gj.execute();
mProgressBar.setVisibility(View.VISIBLE);
這是gridadapter我猜是什麼原因造成的問題
LayoutInflater inflater = LayoutInflater.from(mcontext);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ViewHolder();
我打電話gridimage這樣 GridViewAdapter adapter = new GridViewAdapter(this, R.layout.grid_item_layout, Listitem);
我的問題:我希望能夠膨脹我mainactivity以添加工具欄然而在gridview中的膨脹阻止了我。如何fx的?
public class GridViewAdapter extends ArrayAdapter<GridImages> {
private Context mContext;
private int layoutResourceId;
private ArrayList<GridImages> mGridImages = new ArrayList<GridImages>();
public GridViewAdapter(Context mContext, int layoutResourceId, ArrayList<GridImages> mGridImages) {
super(mContext, layoutResourceId, mGridImages);
this.layoutResourceId = layoutResourceId;
this.mContext = mContext;
this.mGridImages = mGridImages;
}
/**
* Updates grid data and refresh grid items.
* @param mGridData
*/
public void setGridData(ArrayList<GridImages> mGridImages) {
this.mGridImages = mGridImages;
}
添加按鈕'公共類GridViewActivity擴展AppCompatActivity { @覆蓋 保護無效onCreate(Bundle savedInstanceState) {super_onCreate(savedInstanceState); setContentView(R.layout.activity_main); RelativeLayout layout =(RelativeLayout)findViewById(R.id.relativeLayout); Button btnTag = new Button(this); btnTag.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT)); btnTag.setText(「DynAdded Button」); layout.addView(btnTag); } }' – BNK
添加爲答案它會更清晰,我和病態upvote你 – Moudiz