プロジェクトにa をセットアップしlistfragment
ました。しかし、私のフラグメントはアダプターで正しく取得できないようです。そのためContext context
ですMyListAdapter
。クリックして修正すると。に変わりますMenuFragment menuFragment
。しかし、その変更後、MyListAdapter
エラーが発生しました。だから私はそれを修正します。に変わりますContext context
。もう一度修正しても、まだ続きます。そのようにループします。
注: 私が達成したいのは、アイコン付きの ListFragment です。以前の私の他の質問のように(残念ながら誰も答えません)。
public class MenuFragment extends ListFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String [] proMenu ={ "Homies", "Best Nearby", "Coupon" , "Profile" , "History" , "", "Setting" ,
"About" , "Sign Out"};
setListAdapter(new MyListAdapter(this, proMenu));
}
@Override
public void onListItemClick(ListView lv, View v, int position, long id) {
Fragment newContent = null;
switch (position) {
case 0:
newContent = new ColorFragment();
break;
case 1:
Intent intent7 = new Intent();
intent7.setClass(getActivity(), Home.class);
intent7.putExtra("index", position);
startActivity(intent7);
break;
編集:これは私のレイアウトです。今は完全に問題ありません。単語が半分にならないように、テキストビューと線形レイアウトを微調整するだけです。しかし、私は別の問題に直面しています。背景画像が互いに積み重なっているようなものです。これは私のレイアウトのxmlです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:cacheColorHint="#00000000"
android:background="@drawable/menu_drawer">
<ImageView
android:id="@+id/row_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="10dp"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/row_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:padding="10dp"
android:text="Medium Text"
android:textSize="20dp"
android:textAppearance="@android:style/TextAppearance.Medium" />
</LinearLayout>
そして、これandroid:background="@drawable/menu_drawer"
を から削除するとlinear layout
。完璧な背景になります。互いに積み重ならない。しかし、リストをスワイプすると、背景が狂ってしまい、黒い背景が表示されます。listview の問題と似ていandroid:cacheColorHint="#00000000"
ます。私はすでにそれを追加しcachecolor
ましたlinear layout
。しかし、まだ黒い背景が表示されています。こんな感じです。
私は問題が何であるかを知っています。デフォルトの背景が黒だからです。しかし、私はそれを解決する方法がわかりません。
EDIT2 : 黒の問題が解決しました。
解決しました。