5

Fragment使用嵌套listview闪退

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class babyFragment extends Fragment {
ListView lv_main;//页面整体list显示
babyViewPagerAdapter babyFramentAdapter;
//启动页面
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.a, null);

    FragmentManager fm = getActivity().getSupportFragmentManager();
    babyFramentAdapter = new babyViewPagerAdapter(getActivity(), fm);
    lv_main = (ListView) v.findViewById(R.id.listview);
    lv_main.setAdapter(babyFramentAdapter);
    return v;
}

}

import android.content.*;
import android.support.v4.app.*;
import android.view.*;
import android.widget.*;
import kabu.love.zwy.*;

public class babyViewPagerAdapter extends BaseAdapter
{
FragmentManager fm;
public babyViewPagerAdapter(Context pContext, FragmentManager fm_tmp) {
this.mContext = pContext;
fm = fm_tmp;
}
Context mContext;
@Override
public int getCount() {
return 2;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
switch (i) {
case 0:
view = _LayoutInflater.inflate(
R.layout.mc, viewGroup, false);
babyFragment mOneFrament = new babyFragment();
FragmentTransaction babyInfotransaction = fm.beginTransaction();
babyInfotransaction.add(R.id.listview, mOneFrament).commit();
TextView k=(TextView) view.findViewById(R.id.kabu);
k.append("k");
break;
case 1:
view = _LayoutInflater.inflate(
R.layout.mc, viewGroup, false);
babyFragment mTwoFrament = new babyFragment();
FragmentTransaction feedArchivestransaction = fm.beginTransaction();
feedArchivestransaction.add(R.id.listview, mTwoFrament).commit();
TextView y=(TextView) view.findViewById(R.id.kabu);
y.append("y");
break;
case 2://

            break;
        case 3://

            break;
        case 4://

            break;
        case 5://

            break;
    }
    return view;
}

}

谁帮忙解决一下,打开程序停留1秒闪退,

查看全部
qq_35750180
卡布。
2017/07/24 18:13
  • java
  • android
  • 点赞
  • 收藏
  • 回答
    私信

1个回复