我有一個的FrameLayout作爲一個滑動抽屜,我是用片段取代的內容。當我的活動開始時,FrameLayout被一個GridView片段取代。當我點擊GridView中的一個項目時,它將用TextView片段替換FrameLayout。這個新的片段有一個返回的按鈕,並用GridView片段再次替換FrameLayout。這一切都可以正常工作,但由於某種原因,GridView和TextView在更改時都沒有刷新,但是當我點擊一個從服務器獲取信息的按鈕之後,該信息會在新信息刷新時顯示。有沒有辦法讓android認爲我需要重繪GridView和TextView?我已經嘗試過在所有地方都無效(),它似乎沒有絲毫工作。看起來像android正在調用GridView適配器上的「getView」方法,然後它刷新,但是當片段更改爲gridview時從未調用過。GridView的片段不清爽
很抱歉的混亂問題和解釋,我真的不知道作什麼崗位代碼,因爲有這麼多。我會根據請求更新代碼。請幫忙!謝謝。
這裏是上單擊框架佈局被替換爲一個TextView佈局:
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是什麼:
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:
<?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上單擊一個項目時,它會用一個新的「topFrag」(首先顯示)替換framelayout(主佈局),該按鈕通過按鈕使用textview佈局擴展片段。我只是想在點擊一個項目後更新hello。感謝您的期待!
我試圖做一個notifyDataSetChanged()爲GridView並不會影響它在所有。我用更簡單的文本視圖進行編輯。感謝您的嘗試! – coolbox
原來,片段的onStart方法需要在其中設置文本。謝謝您的幫助! – coolbox