卡布。 2017-07-24 18:13 采纳率: 42.9%
浏览 1324
已结题

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秒闪退,

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 用java解决,要解释一下给我
      • ¥100 项目经理想学开发牛牛指点迷津有偿
      • ¥15 vscode 配置时出现问题
      • ¥15 pygame安装失败
      • ¥15 数据库原理怎么从文字描述中的句子推出(分析)函数依赖?
      • ¥15 想要使用有序logistic模型,因变量收集结果为以下,可以继续分析吗?
      • ¥15 C语言的问题 求尽快解答一下
      • ¥15 sql相关子查询的一道选择题
      • ¥15 关于图像检测的问题#
      • ¥15 用cemu8086编写代码