我有mainactivity
和gridimageactivity
我注意到gridimageactivity正在膨胀主要活动布局。我想在R.main_activity中添加新的按钮和东西。
这是主要活动,因为您注意到我评论了布局,但应用程序仍在显示文本视图和图像。
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);
我的问题:我希望能够扩充我的主要活动以添加工具栏,但是gridview中的膨胀阻止了我。怎么样这个?
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;
}
答案 0 :(得分:1)
如评论所述,请尝试以下(在GridViewActivity中添加使用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);
}
}
但是,您应该检查它是否适用于您的项目。
更新:
<强> row_grid.xml:强>
我在上一个问题中的答案:
customGridAdapter = new CustomGridViewAdapter(mContext, R.layout.row_grid, gridArray);