スライディングドロワーのコンテンツとしてFrameLayoutがあり、フラグメントに置き換えています。アクティビティが開始されると、FrameLayoutはGridViewフラグメントに置き換えられます。GridViewのアイテムをクリックすると、FrameLayoutがTextViewフラグメントに置き換えられます。この新しいフラグメントには、戻るボタンがあり、FrameLayoutを再びGridViewフラグメントに置き換えます。これはすべて正常に機能しますが、何らかの理由で、に変更してもGridViewもTextViewも更新されませんが、サーバーから情報を取得するボタンをクリックすると、その時点で表示されているボタンが新しい情報で更新されます。GridViewとTextViewを再描画する必要があるとAndroidに思わせる方法はありますか?私はすべての場所でinvalidate()を試しましたが、少しも機能していないようです。Androidが「getView」を呼び出しているようです
紛らわしい質問と説明で申し訳ありませんが、たくさんあるので、どのコードを投稿すればよいかわかりません。リクエストに応じてコードで更新します。助けてください!ありがとうございました。
クリックすると、フレームレイアウトがテキストビューレイアウトに置き換えられます。
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);
}
}
内部にフレームレイアウトがあるメインレイアウト:
<?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」(最初に表示)に置き換えられ、ボタン付きのテキストビューレイアウトでフラグメントが膨らみます。アイテムがクリックされた後、これでhelloを更新したいだけです。見てくれてありがとう!