SliderView使用碎片

时间:2014-06-30 14:05:29

标签: android android-fragments slider fragment

我正在开发一个应用程序,其中使用了tablayout,其中显示了4个标签,这是一个片段。我的选项卡之一我使用的是一个滑动条,其中我显示了4个选项的列表视图,现在我被卡住了在其click事件中。我希望在listview上打开一个新的布局click.Searched很多但没有获得与片段相关的单个代码。请帮帮我。谢谢你的帮助

NewChattFragment:

public class NewChatFragment extends Fragment

{

    private DrawerLayout drawerLayout; 

    private View drawerView;

    private ListView listView1;

    private ArrayList<drawer> arrayProvider;

    private drawerAdapter adapter;


   @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

   @SuppressLint("NewApi") @Override

   public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

    View v = inflater.inflate(R.layout.newchatfragment_layout, container, false);

    arrayProvider = new ArrayList<drawer>();
    arrayProvider.add(new drawer("1-to-1"));
    arrayProvider.add(new drawer("Group"));
    arrayProvider.add(new drawer("Video Call"));
    arrayProvider.add(new drawer("Broadcast"));
    arrayProvider.add(new drawer("Blink"));

    listView1 = (ListView) v.findViewById(R.id.left_drawer);

    adapter = new drawerAdapter(getActivity(), arrayProvider);

     listView1.setAdapter(adapter);

     drawerLayout = (DrawerLayout) v.findViewById(R.id.drawer_layout);

     drawerView = (View)v.findViewById(R.id.drawer);

     drawerLayout.openDrawer(drawerView);

    return v;
    }
}

1 个答案:

答案 0 :(得分:0)

请参阅此课程以创建导航列表,并获取其列表视图,希望这对您有所帮助,

    public class NavigationListFragment extends ListFragment {

    private static final String TAG = NavigationListFragment.class.getName();

    MenuAdapter menuAdapter;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.navigation_list, null);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        menuAdapter = new MenuAdapter(getActivity());

        menuAdapter.add(new MenuItem("1-to-1", R.drawable.search_icon_select));
        menuAdapter.add(new MenuItem("Group", R.drawable.cuse_icon));
        menuAdapter.add(new MenuItem("Video Call", R.drawable.cart_icon));
        menuAdapter.add(new MenuItem("Broadcast", R.drawable.post_icon));
        menuAdapter.add(new MenuItem("Blink", R.drawable.settting_icon));

        getListView()
                .setDivider(new ColorDrawable(Color.parseColor("#FFFFFF")));
        getListView().setDividerHeight(1);

        setListAdapter(menuAdapter);
    }

    private class MenuItem {
        public String tag;
        public int iconRes;

        public MenuItem(String tag, int iconRes) {
            this.tag = tag;
            this.iconRes = iconRes;
        }
    }

    public class MenuAdapter extends ArrayAdapter<MenuItem> {

        public MenuAdapter(Context context) {
            super(context, 0);
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(
                        R.layout.cell_navigation, null);
            }
            ImageView icon = (ImageView) convertView
                    .findViewById(R.id.row_icon);
            icon.setImageResource(getItem(position).iconRes);
            TextView title = (TextView) convertView
                    .findViewById(R.id.row_title);
            title.setText(getItem(position).tag);

            return convertView;
        }
    }

    @Override
    public void onListItemClick(ListView lv, View v, int position, long id) {
        switch (position) {
        case 0:
            //click event for 1-to-1
            break;

        case 1:
            //click event for Group
            break;

        case 2:
            //click event for Video Call
            break;

        case 3:
            //click event for Broadcast
            break;

        case 4:
            //click event for Blink
            break;
        }
    }
}