I have an adapter with gridview that works like an Activity. I am trying to put it in a Fragment now and convert things, but that will not work. When I include an IconFragmentSystem in my activity, I gain strength when I try to open an Activity.
I know that activity works because I can use other fragments, and everything is fine, so I know that my problem lies in this file.
package com.designrifts.ultimatethemeui; import com.designrifts.ultimatethemeui.R; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.*; import java.util.ArrayList; public class IconFragmentSystem extends Fragment implements AdapterView.OnItemClickListener{ private static final String RESULT_OK = null; public Uri CONTENT_URI; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.main, container, false); super.onCreate(savedInstanceState); int iconSize=getResources().getDimensionPixelSize(android.R.dimen.app_icon_size); GridView gridview = (GridView) getActivity().findViewById(R.id.icon_grid); gridview.setAdapter(new IconAdapter(this, iconSize)); gridview.setOnItemClickListener(this); CONTENT_URI=Uri.parse("content://"+iconsProvider.class.getCanonicalName()); return view; } @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String icon=adapterView.getItemAtPosition(i).toString(); Intent result = new Intent(null, Uri.withAppendedPath(CONTENT_URI,icon)); setResult(RESULT_OK, result); finish(); } private void setResult(String resultOk, Intent result) {
I tried different ways to implement this, but they all failed, and I really could use the help pointing me in the right direction.
This is my xml in layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <GridView android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:columnWidth="90dp" android:numColumns="auto_fit" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:stretchMode="columnWidth" android:gravity="center" /> </RelativeLayout>
source share