2016-06-14 2 views
0

Das ist also eine Fragmentklasse. Ich versuche, einige Elemente zu listview mit Baseadaptor hinzufügen. Ich bin ein Anfänger, also bin ich dieser Frage gefolgt. How to customize listview using baseadapter Aber jetzt bekomme ich Setcontentview Fehler (Fehler konnte nicht behoben werden) bei Zeile Nr. 72 und innerer Klassenfehler bei 147. Also bitte hilf mir, es zu reparieren. Paketlayout;Wie beheben Sie Setcontentview Fehler und innere Klassenfehler in dieser Fragmentklasse?

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); 
    } 






     } 
    } 
+0

Entfernen Sie 'setContentView (R.layout.fragment_ussd);' in Ihrem 'onCreateView()'. Sie brauchen es nicht in einem Fragment – SripadRaj

+0

Warum nicht bekommen "unerreichbar Code nach Return-Anweisung" Warnung –

+0

Danke behoben @SripadRaj aber was ist mit dem 2. Fehler .. – bucky

Antwort

0

In Ihrem onCreateView Sie das aufgeblasene Layout auf der ersten Zeile zurückkehren. ändern Sie es in

@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; 
     } 
+0

Dank es funktioniert aber immer noch bei zweiten Fehler stecken – bucky

+0

@Bucky was ist der zweite Fehler ? –

+0

innere Klasse kann keine statische Deklaration an der Zeile Nr. Haben. 148 – bucky