I am making small bubble words game where there will be many bubble(Imageview) on the screen. Now there will be 15 bubbles already placed on the levelScreen…There will be three levels… Say first Level with its bg and its 15 objects in one layout level.xml
This is my xml for level1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/gmw_01"
android:onClick="onClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/relativeLayout1" >
<ImageView
android:onClick="objectClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/bb01"
android:layout_marginLeft="998dp"
android:layout_marginTop="593dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
<ImageView
android:onClick="objectClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/bb02"
android:layout_marginLeft="20dp"
android:layout_marginTop="39dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
<ImageView
android:onClick="objectClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/imageView3"
android:src="@drawable/bb03"
android:layout_marginLeft="497dp"
android:layout_marginTop="153dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"/>
like that 15 Imageview which contains 15 bubbles in above layout….
Now I have one screen where level is selected and depending I put the level1 in that gamplayScreen.xml i.e. i inflate it in the gamePlayScreen which has Headup display at the left and this level screen which will keep on changing….
Before inflating my level on the gamePlayScreen …. I want to pickup random 8 bubbles which can be only clickable by user. At every level there will be 15 bubbles visible but i want to pick random 8 every level depending on the respective bubbles at that level…
here is the gamePlayActivity
public class GamePlayActivity extends Activity {
static int ObjectsFound;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameplay);
// ViewGroup where n number of view is going to added
ViewGroup layout= (ViewGroup) findViewById(R.id.GamePlayScreen);
// inflating the layout depending on the level
View level = View.inflate(this, LevelSelectionActivity.levelscreen, null);
// adding level bg for the respective selected level
layout.addView(level);
}
public void objectClick(View objectClicked)
{
Toast msg;
int Object = objectClicked.getId();
ImageView img= (ImageView)findViewById(objectClicked.getId());
switch (Object) {
case R.id.imageView1:
img.setVisibility(View.INVISIBLE);
msg = Toast.makeText(GamePlayActivity.this, "Bubble Found", Toast.LENGTH_SHORT);
msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2, msg.getYOffset() / 2);
msg.show();
break;
}
}
Now how to perform that random 8 objects out of the 15 object that I have in ImageView i want to set them as nonclickable ?
I hope i have explained the thing where i m too confused …
Pseudocode, haven’t tested this but should work for you:
Basically we pick 8 random views and set them as non-clickable. If we nail a view that was already made not clickable (because we’ve made it so at a previous step) we repick. Good luck!