I want to get the id's of my imageviews in my ObjectsClass which are in level1.xml and I have inflated this layout in GamePlayActivity...MY ObjectClass is not activity then how to get array of id's in that class ...here is my level.xml say there are 15 ImageView I have just shown few ....
<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"/>
and here is my 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);
** getRandom(); // here I want to call that random because this should be done before my level is added on the view**
// 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;
}
}
and the ObjectClass
public class Objects {
int ObectId[];
Objects(Context context)
{
super();
for(int i=0;i<15;++i)
{
**ObectId[i]=R.id.;** // what to get it over here ? ? ?
}
}
public void randomize() {
Random generator = new Random();
for(int i = 0; i<8 ; i++) {
while(true) {
**View v = findViewById(generator.nextInt(Objectid.length));**
if(!v.isClickable()) {
v.setClickable(false);
break;
}
}
}
}
}
at the end I want random number of objects to be unclickable i.e. out of 15 objects everytime user can have only 8 objects clickable on the screen so before my level starts i.e. before I inflate in my gameplayActivity as seen above I want to get random 8 clickable and vice versa...
Adding to that it should work for all level ...right now I have one level1.xml how to achieve it for all levels... do i need to give same id's of image view in all layout ?