2

I have a FrameLayout as the content of a sliding drawer that i'm replacing with fragments. When my activity starts the FrameLayout is replaced by a GridView Fragment. When i click on an item in the GridView it replaces the FrameLayout with a TextView fragment. This new fragment has a button that goes back and replaces the FrameLayout again with a GridView Fragment. This all works fine but for some reason neither the GridView nor the TextView refreshes when changed to, but after i click on a button that gets info from a server which ever one is visible at the time refreshes with the new information. Is there a way to make android think i need to redraw the GridView and TextView? I've tried invalidate() about everywhere on everything and it doesn't seem to work in the slightest. It seems like android is calling the "getView" method on the GridView Adapter and then it refreshes but that is never called when the fragment changes to the gridview.

Sorry for the confusing question and explanation, i don't really know what code to post since there is so much. I will update with code on request. Please Help! Thank you.

Here is where on click the frame layout is replaced with a textview layout :

    playerGridView = (GridView) findViewById(R.id.playerInfoGrid);
    if (playerGridView != null) {
        playerGridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                drawerFragment2 = new topFrag();
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.frag_content, drawerFragment2);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        });
    }

Here is what the topFrag is :

public class topFrag extends Fragment {

private TextView view;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.slidingdrawer2, container, false);
}

@Override
public void onStart() {
    super.onStart();
    view = (TextView) getView().findViewById(R.id.characterInfo);
    view.setText("hello");
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}
}

Main layout that has the framelayout inside:

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >    
<SlidingDrawer
     android:id="@+id/drawer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:topOffset="125dip"
     android:handle="@+id/handle" 
     android:content="@+id/frag_content">

    <ImageView 
        android:id="@+id/handle" 
        android:contentDescription="@string/handle"
        android:layout_width="120dip" 
        android:layout_height="30dip"
        android:src="@drawable/drawertab"/>

    <FrameLayout
        android:id="@+id/frag_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</SlidingDrawer>

</RelativeLayout>

Here is what i replace the framelayout with:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#50808080" >

<TextView
    android:id="@+id/characterInfo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/playerInfoBack"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#FFFFFF" />

<Button
    android:id="@+id/playerInfoBack"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="@string/back"
    android:onClick="back" />

</RelativeLayout>

No idea if this helps or just makes it far more confusing.

When you Click an Item on the playerGridView it replaces the framelayout (main layout) with a new "topFrag" (shown first) which inflates the fragment with the textview layout with a button. I just want this to update hello after an item is clicked. Thanks for looking!

1 Answer 1

0

For the GridView you would call notifyDataSetChanged() on the adapter backing the GridView so that it knows to update.

For the TextView I'd have to see the code to understand what is going on there.

2
  • I tried doing a notifyDataSetChanged() for the gridview and that does not effect it at all. I edited with the easier one which is the textview. Thanks for trying!
    – coolbox
    Nov 16, 2012 at 4:53
  • Turns out the onStart method for the fragment needs to set the text in there initially. Thanks for the help!
    – coolbox
    Nov 16, 2012 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.