包含Gridview的片段,其中包含可点击的照片(图库)

时间:2012-08-05 18:13:22

标签: android gridview android-fragments gallery

我正在尝试创建的是一个片段,其中包含一个充满可点击图片的GridView。

我搜索了很多地方.. Normal Grid GridView Frag

并以某种方式尝试将它们一起工作......但似乎没有那样做

/////活动类/////

public static class ChampionFragment extends Fragment {

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

        System.out.println("Inside onCreateView");

        String[] champList = getResources().getStringArray(R.array.championList);
        System.out.println("Got champList");

        View champView = inflater.inflate(R.layout.champion_menu, container, false);
        System.out.println("inflater");

        /*
        ArrayAdapter<String> arrayAptr = new ArrayAdapter<String>(this.getActivity().getApplicationContext(), R.layout.champion_menu,champList);
        System.out.println("Created array Adapter");

        //GridView grid = (GridView)champView.findViewById(R.id.champView);
        System.out.println("Grided");

        grid.setAdapter(arrayAptr);
        System.out.println("Set Adapter");
        */

        return  champView;
        //ArrayList champList = getChampionList();
    }
}

/////布局////

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/champView"
    android:numColumns="auto_fit"
    android:gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</GridView>

所以是的,我尝试了很多方法......我不知道如何让它发挥作用 非常感谢帮助!

1 个答案:

答案 0 :(得分:0)

您应该使用不同的方法设置数据和适配器

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

然后你需要设置一个onItemClickLister

champView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), SomeActivity.class);
            startActivity(intent);
        }
    });