2012-11-16 6 views
2

프래그먼트로 대체되는 슬라이딩 서랍의 내용으로 FrameLayout이 있습니다. 내 활동이 시작되면 FrameLayout이 GridView Fragment로 바뀝니다. GridView에서 항목을 클릭하면 TextView 조각으로 FrameLayout을 대체합니다. 이 새로운 조각에는 FrameLayout을 다시 GridView Fragment로 대체하는 버튼이 있습니다. 이 모든 잘 작동하지만 변경된 경우 GridView도 TextView도 새로 고쳐지지 않습니다. 그러나 시간이 지나면 볼 수있는 서버에서 정보를 가져 오는 단추를 클릭하면 새 정보가 새로 고쳐집니다. 안드로이드가 GridView와 TextView를 다시 그릴 필요가 있다고 생각하는 방법이 있습니까? 나는 모든 것에 대해 무효화()를 시도했으나 조금이라도 작동하지 않는다. 그것은 안드로이드 GridView 어댑터에 대한 "getView"메서드를 호출하고 새로 고칩니다 있지만 그 fragmentView gridview 변경 될 때 결코 호출되는 것 같습니다.Gridview 프래그먼트가 새로 고침되지 않습니다.

혼란스러운 질문과 설명에 대해 유감스럽게 생각합니다. 게시 할 코드가 너무 많아서 실제로 알지 못합니다. 나는 요청에 따라 코드를 업데이트 할 것이다. 도와주세요! 고맙습니다.

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); 
} 
} 
내부의 FrameLayout이있다

홈페이지 레이아웃 :

다음
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(); 
      } 
     }); 
    } 

가 topFrag이 무엇이다 :에 프레임 레이아웃을 클릭하는 위치 여기

는 텍스트 뷰 레이아웃으로 대체됩니다

<?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> 

여기 framelayout을 다음으로 대체합니다.

<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> 

이 정보가 도움이되는지 아니면 훨씬 더 혼란 스러울 지에 대해서는 알 수 없습니다.

playerGridView에서 항목을 클릭하면 framelayout (주 레이아웃)이 새로운 "topFrag"(첫 번째로 표시됨)로 바뀌어 버튼이있는 textview 레이아웃으로 조각이 팽창됩니다. 난 그냥 항목을 클릭 한 후 안녕하세요를 업데이 트하고 싶습니다. 보고 주셔서 감사합니다!

답변

0

GridView의 경우 GridView를 지원하는 어댑터에서 notifyDataSetChanged()을 호출하여 업데이트를 알 수 있습니다.

TextView의 경우에는 코드가 어떻게 진행되고 있는지 이해해야합니다.

+0

gridview에 대한 notifyDataSetChanged()를 시도했는데 전혀 영향을 미치지 않습니다. 나는 textview 인 더 쉬운 것으로 편집했다. 노력해 주셔서 감사합니다! – coolbox

+0

조각에 대한 onStart 메서드가 처음에는 텍스트를 설정해야합니다. 도와 주셔서 감사합니다! – coolbox

관련 문제