How To Fix The Inflation Another R.layout
I have mainactivity and gridimageactivity I Noticed that gridimageactivity is inflating the mainactivity layout. I want to add new buttons and thing in the R.main_activity. this is
Solution 1:
As commented, please try the following (sample for adding a button inside GridViewActivity which uses layout_main.xml).
public class GridViewActivity extends AppCompatActivity {
@Override
protected void 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("Dynamic Added Button");
layout.addView(btnTag);
}
}
However, you should check if it works for your project or not.
UPDATE:
row_grid.xml:
My answer in your previous question:
customGridAdapter = new CustomGridViewAdapter(mContext, R.layout.row_grid, gridArray);
Post a Comment for "How To Fix The Inflation Another R.layout"