0

嗨,不知道如何在我的SerlockListFragment. 这是我的活动

public class FavoritosFragment extends SherlockListFragment {

    SharedPreferences app_preferences;
    boolean tv1, tv2, tv3, tv4, tv5, tv6, radio1, radio2, radio3, radio4, radio5, radio6;
    boolean primeraPos, segundaPos, terceraPos, cuartaPos, quintaPos, sextaPos, septimaPos, octavaPos, novenaPos,
        decimaPos, undecimaPos, duodecimaPos;

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

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

        //////////////////////////guardar variables en SharedPreferences//////////////////////////////////
        app_preferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
        final SharedPreferences.Editor editor = app_preferences.edit();
        final boolean tv1=app_preferences.getBoolean("tv1", false);
        final boolean tv2=app_preferences.getBoolean("tv2", false);
        final boolean tv3=app_preferences.getBoolean("tv3", false);
        final boolean tv4=app_preferences.getBoolean("tv4", false);
        final boolean tv5=app_preferences.getBoolean("tv5", false);
        final boolean tv6=app_preferences.getBoolean("tv6", false);
        final boolean radio1=app_preferences.getBoolean("radio1", false);
        final boolean radio2=app_preferences.getBoolean("radio2", false);
        final boolean radio3=app_preferences.getBoolean("radio3", false);
        final boolean radio4=app_preferences.getBoolean("radio4", false);
        final boolean radio5=app_preferences.getBoolean("radio5", false);
        final boolean radio6=app_preferences.getBoolean("radio6", false);

        // Each row in the list stores name, category and image
        final List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();

        if(tv1==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "RNB");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }

        if(tv2==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "POP ROCK");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        if(tv3==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "ARTISTS");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }

        if(tv4==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "ELECTRO");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        if(tv5==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "LATINO");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }
        if(tv6==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "100% ROCK");
            hm.put("subTitulo", "CANAL TV");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        if(radio1==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "80s");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }

        if(radio2==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "DANCE");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        if(radio3==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "LATINO");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }

        if(radio4==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "RELAX");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        if(radio5==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "HIP HOP");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.rock));
            aList.add(hm);
        }
        if(radio6==true){
            HashMap<String, String> hm = new HashMap<String,String>();
            hm.put("txt", "ROCK");
            hm.put("subTitulo", "ESTACION DE RADIO");
            hm.put("img", Integer.toString(R.drawable.pop));
            aList.add(hm);
        }

        // Keys used in Hashmap
        String[] from = { "img","txt","subTitulo"};

        // Ids of views in listview_layout
        int[] to = { R.id.img,R.id.txt, R.id.subTitulo};

        // Instantiating an adapter to store each items
        // R.layout.listview_layout defines the layout of each item
        SimpleAdapter adapter = new SimpleAdapter(getActivity().getBaseContext(), aList, R.layout.favoritos_fragment, from, to);


        // Setting the adapter to the listView
        setListAdapter(adapter);
        return super.onCreateView(inflater, container, savedInstanceState);
    }    

    public void onListItemClick(ListView l, View v, int position, long id){
        super.onListItemClick(l, v, position, id);

        app_preferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
        final SharedPreferences.Editor editor = app_preferences.edit();

        final String codeS= app_preferences.getString("codeS", "795006");
        final String keyS = app_preferences.getString("keyS", "testandroid");

        String urlReproducir = null;
        String tipoReproducir=null;
        Object o = this.getListAdapter().getItem(position);
        HashMap fullObject = (HashMap) o;

        String categoriaInicial=(String) fullObject.get("txt");
        String tipoInicial = (String) fullObject.get("subTitulo");

        String categoria2=categoriaInicial.toLowerCase();
        String tipo2 = tipoInicial.toLowerCase();

        String categoriaFinal = categoria2.replaceAll("\\s+","");
        String tipoFinal = tipo2.replaceAll("\\s+",""); 

        Log.d("categoriaFinal",categoriaFinal);
        Log.d("tipoFinal",tipoFinal);

        if(categoriaFinal.compareTo("rnb")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/301.json";
            tipoReproducir="tv";
        }
        else if(categoriaFinal.compareTo("poprock")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/296.json";
            tipoReproducir="tv";
        }
        else if(categoriaFinal.compareTo("artists")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/298.json";
            tipoReproducir="tv";
        }
        else if(categoriaFinal.compareTo("electro")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/297.json";
            tipoReproducir="tv";
        }
        else if(categoriaFinal.compareTo("latino")==0){
            if(tipoFinal.compareTo("canaltv")==0){
                urlReproducir="http://vod.infomaniak.com/playlist/293.json";
                tipoReproducir="tv";
            }
            else{
                urlReproducir="http://vod.infomaniak.com/playlist/337.json";
                tipoReproducir="radio";
            }
        }
        else if(categoriaFinal.compareTo("100%rock")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/300.json";
            tipoReproducir="tv";
        }
        else if(categoriaFinal.compareTo("80s")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/402.json";
            tipoReproducir="radio";
        }
        else if(categoriaFinal.compareTo("dance")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/380.json";
            tipoReproducir="radio";
        }
        else if(categoriaFinal.compareTo("relax")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/360.json";
            tipoReproducir="radio";
        }
        else if(categoriaFinal.compareTo("hiphop")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/381.json";
            tipoReproducir="radio";
        }
        else if(categoriaFinal.compareTo("rock")==0){
            urlReproducir="http://vod.infomaniak.com/playlist/403.json";
            tipoReproducir="radio";
        }
        switch(position){
            case 0:
                Log.d("urlReproducir",urlReproducir);
                //Intent intent = new Intent(getActivity().getApplicationContext(), Reproductor.class);
                //intent.putExtra("xml", urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i.putExtra("code", codeS);
                i.putExtra("keyword", keyS);
                i.putExtra("suscrito", false);
                startActivityForResult(i, 1);
            break;
            case 1:
                Log.d("urlReproducir",urlReproducir);
                //Intent intent1 = new Intent(getActivity().getApplicationContext(), Reproductor.class);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i1 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i1.putExtra("code", codeS);
                i1.putExtra("keyword", keyS);
                i1.putExtra("suscrito", false);
                startActivityForResult(i1, 1);
            break;
            case 2:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i2 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i2.putExtra("code", codeS);
                i2.putExtra("keyword", keyS);
                i2.putExtra("suscrito", false);
                startActivityForResult(i2, 1);
            break;
            case 3:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i3 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i3.putExtra("code", codeS);
                i3.putExtra("keyword", keyS);
                i3.putExtra("suscrito", false);
                startActivityForResult(i3, 1);
            break;
            case 4:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i4 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i4.putExtra("code", codeS);
                i4.putExtra("keyword", keyS);
                i4.putExtra("suscrito", false);
                startActivityForResult(i4, 1);
            break;
            case 5:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i5 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i5.putExtra("code", codeS);
                i5.putExtra("keyword", keyS);
                i5.putExtra("suscrito", false);
                startActivityForResult(i5, 1);
            break;
            case 6:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i6 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i6.putExtra("code", codeS);
                i6.putExtra("keyword", keyS);
                i6.putExtra("suscrito", false);
                startActivityForResult(i6, 1);
            break;
            case 7:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i7 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i7.putExtra("code", codeS);
                i7.putExtra("keyword", keyS);
                i7.putExtra("suscrito", false);
                startActivityForResult(i7, 1);
            break;
            case 8:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i8 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i8.putExtra("code", codeS);
                i8.putExtra("keyword", keyS);
                i8.putExtra("suscrito", false);
                startActivityForResult(i8, 1);
            break;
            case 9:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i9 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i9.putExtra("code", codeS);
                i9.putExtra("keyword", keyS);
                i9.putExtra("suscrito", false);
                startActivityForResult(i9, 1);
            break;
            case 10:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i10 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i10.putExtra("code", codeS);
                i10.putExtra("keyword", keyS);
                i10.putExtra("suscrito", false);
                startActivityForResult(i10, 1);
            break;
            case 11:
                Log.d("urlReproducir",urlReproducir);
                editor.putString("url", urlReproducir);
                editor.putString("tipo",tipoReproducir);
                editor.commit();
                Intent i11 = new Intent(getActivity().getApplicationContext(), Subscription.class);
                i11.putExtra("code", codeS);
                i11.putExtra("keyword", keyS);
                i11.putExtra("suscrito", false);
                startActivityForResult(i11, 1);
            break;

        }

    }

这是我的布局

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android">


        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="10dp">
            <RelativeLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:background="#fff"
                android:padding="10dp" >

                <ImageView 
                    android:id="@+id/img"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/hello_world"
                    android:layout_alignParentLeft="true" />
                <LinearLayout 
                        android:id="@+id/contenedor1LL"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_toRightOf="@id/img"
                        android:orientation="vertical"
                        android:paddingLeft="10dp">

                    <TextView 
                        android:id="@+id/txt"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="20sp"
                        android:textColor="#000"
                        android:textStyle="bold"
                        android:layout_centerVertical="true"
                         />
                    <TextView 
                        android:id="@+id/subTitulo"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textSize="17sp"
                        android:textColor="#FF8000"/>
                </LinearLayout>

            </RelativeLayout>
        </LinearLayout> 
        <LinearLayout 
            android:layout_height="wrap_content" 
            android:layout_width="fill_parent"
            android:layout_alignParentBottom="true"
            android:background="#000"> 
            <RelativeLayout 
                android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:id="@+id/top_control_bar" 
                android:layout_alignParentBottom="true"> 
                <ScrollView 
                    android:layout_height="80dp" 
                    android:layout_width="wrap_content" 
                    android:id="@+id/legalesSV" 
                    android:layout_above="@+id/terminosBtn"> 

                    <TextView 
                        android:layout_height="wrap_content" 
                        android:layout_width="match_parent" 
                        android:textStyle="bold" 
                        android:textSize="10sp" 
                        android:textColor="#333" 
                        android:text="@string/footer_suscripcion" 
                        android:id="@+id/footerTV" 
                        android:textAlignment="center" 
                        android:paddingLeft="10dp" 
                        android:paddingRight="10dp"/> 
                  </ScrollView> 
            </RelativeLayout> 
        </LinearLayout>
</RelativeLayout>    

我得到的是一个带有图像的列表视图,两个文本以及页脚文本视图,它在每一行中重复。有人知道答案吗?

谢谢

4

1 回答 1

0

我所做的是在包含片段的主要活动中添加页脚。最后很简单

这是我的代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="100dp"
     />
    <ScrollView 
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="100dp">
        <TextView 

            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000"
            android:text="@string/footer_suscripcion"
            android:textColor="#333"/>
    </ScrollView>
</RelativeLayout>

希望它可以帮助

于 2013-05-30T17:10:46.160 回答