I want to let the user add buttons So that each row are only four buttons. so I wrote the following function:
private void addContact() {
//numButton Count how many buttons there are in line
if(numButton==0){
LinearLayout linearLayout =new LinearLayout(this);
linearLayout.setOrientation(0);//horizontal
ImageButton imageButton =new ImageButton(this);
imageButton.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.button1));
linearLayout.addView(imageButton);
LinearLayout linearbase= (LinearLayout)findViewById(R.id.linearBase);
linearbase.addView(linearLayout);
numButton++;
}
else if(numButton<4)
{
LinearLayout linearlayout= ----####Here I do not know what to write!!!!###
ImageButton imageButton =new ImageButton(this);
imageButton.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.button1));
linearlayout.addView(imageButton);
numButton++;
}
else
{
numButton=0;
}
}
I marked the lines of code my problem Specifically my problem is how to put the new button into the linearlayout that defined in the previous call to this function? Second question: how to keep the new situation even when you close the application?