Hello can anybody tell me why this code give me error and crash my app? This happens only when 'reset((View) child);' is added at the end What I want to do is when I click a Button with onClick:reset, It will apply a kind of reset to only Images and textviews inside a LinearLayout which has more types of childrens
public void reset(View v) {
LinearLayout items = (LinearLayout) findViewById(R.id.itemsToSearch);
for (int i = 0; i < items.getChildCount(); i++)
{
Object child = items.getChildAt(i);
Context context = getApplicationContext();
CharSequence text = child.toString();
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
if (child instanceof ImageView)
{
((ImageView) child).setVisibility(View.INVISIBLE);
}
else if (child instanceof TextView)
{
((TextView) child).setTextColor(Color.parseColor("#98868A"));
}
else if(child instanceof ViewGroup)
{
reset((View) child);
}
}
}
and the other question is that my app works with FragmentPagerAdapter, How can I do for example if I click a Button in Frag#1 it will change a text inside Frag#3 which is currently not shown?, For me it always crash, As I see it is because Frag#3 or whatever other frag which is off screen is not yet loaded on screen and because of that it doesnt fint the specified ID
Thank You