0

So this is a fragment class . I am trying to add some items to listview using baseadaptor. I am a beginner so i followed this question. How to customize listview using baseadapter But now i am getting setcontentview error (Couldn't resolve error) at line no. 72 and inner class error at 147. So please help me in fixing it. package layout;

import android.content.Context;
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.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.buckydroid.app.droidcpu.R;


public class ussd extends Fragment {
    ListView l1;
    String[] t1={"ussd1","ussd2"};
    String[] d1={"le1","ln2"};
    private View myfragment;
    int[] i1 ={R.drawable.ic_launcher,R.drawable.ic_launcher};
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private dataListAdapter.OnFragmentInteractionListener mListener;

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment ussd.
     */
    // TODO: Rename and change types and number of parameters
    public static ussd newInstance(String param1, String param2) {
        ussd fragment = new ussd();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }
    public ussd() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_ussd, container, false);
        myfragment =  inflater.inflate(R.layout.fragment_ussd, container, false);
        //getting error at thus part "cannot resolve setcontentview"
        setContentView(R.layout.fragment_ussd);
        l1=(ListView)myfragment.findViewById(R.id.listView);
        l1.setAdapter(new dataListAdapter(t1,d1,i1));
    }

    class dataListAdapter extends BaseAdapter {
        String[] Title, Detail;
        int[] imge;

        dataListAdapter() {
            Title = null;
            Detail = null;
            imge=null;
        }

        public dataListAdapter(String[] text, String[] text1,int[] text3) {
            Title = text;
            Detail = text1;
            imge = text3;

        }

        public int getCount() {
            // TODO Auto-generated method stub
            return Title.length;
        }

        public Object getItem(int arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {

            LayoutInflater inflater = getLayoutInflater(Bundle.EMPTY);
            View row;
            //getting error at this part too "unconditional layout inflation from view adaptor
            row = inflater.inflate(R.layout.listing, parent, false);
            TextView title, detail;
            ImageView i1;
            title = (TextView) row.findViewById(R.id.title);
            detail = (TextView) row.findViewById(R.id.detail);
            i1=(ImageView)row.findViewById(R.id.img);
            title.setText(Title[position]);
            detail.setText(Detail[position]);
            i1.setImageResource(imge[position]);

            return (row);
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }




    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }






        }
    }
Community
  • 1
  • 1
bucky
  • 57
  • 8

1 Answers1

0

In your onCreateView you are returning the inflated layout on the first line. change it to

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        myfragment =  inflater.inflate(R.layout.fragment_ussd, container, false);
        //getting error at thus part "cannot resolve setcontentview"
        l1=(ListView)myfragment.findViewById(R.id.listView);
        l1.setAdapter(new dataListAdapter(t1,d1,i1));
        return myfragment;
        }
M.Waqas Pervez
  • 2,440
  • 2
  • 19
  • 32