单个活动中的多个ListView

时间:2016-03-15 16:24:38

标签: java android xml listview

所以我需要在列表之间有3个分隔符,我有初学者,中级和高级列表,每个列表上面都有一个不可点击的按钮或任何东西,它只是显示一些文本。< / p>

但是当我对它进行编码时,即使每个列表视图都是单独的LinearLayout并且具有确切的权重,它也无法正确显示。

此处的XML代码

<LinearLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="hr.app.liftme.liftmehr.ListaProgramiBodybuilding"
    android:orientation="vertical"
    tools:showIn="@layout/activity_lista_programi_bodybuilding">


    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_weight="1">

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:id="@+id/buttonProgrami1"
        android:background="#2196f3"
        android:textColor="#ffffff"
        android:text="@string/programi_pocetnici"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:id="@+id/listaProgramiPocetnici">
    </ListView>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#2196f3"
        android:textColor="#ffffff"

        android:id="@+id/buttonProgrami2"
        android:text="@string/programi_srednji"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:id="@+id/listaProgramiSrednji">
    </ListView>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        >

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#2196f3"
        android:textColor="#ffffff"
        android:id="@+id/buttonProgrami3"

        android:text="@string/programi_napredni"/>

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:id="@+id/listaProgramiNapredni">
    </ListView>
    </LinearLayout>

</LinearLayout>

以及这里的Java文件

 ListView listaProgramiPocetnici, listaProgramiSrednji, listaProgramiNapredni;
    ArrayAdapter<String> adapter;
    int onStartCount = 0;

    Integer[] imageId = {R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici,
            R.drawable.ic_ikona_pocetnici
            };

    Integer[] imageId2 = {R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji,
            R.drawable.ic_ikona_srednji};

    Integer[] imageId3 = {R.drawable.ic_ikona_napredni,
            R.drawable.ic_ikona_napredni};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista_programi_bodybuilding);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        onStartCount = 1;
        if (savedInstanceState == null)
        {
            this.overridePendingTransition(R.anim.anim_slide_in_left,
                    R.anim.anim_slide_out_left);
        } else {
            onStartCount = 2;
        }


        AdapterListaVjezbe adapter = new AdapterListaVjezbe(ListaProgramiBodybuilding.this, getResources().getStringArray(R.array.programi_pocetnici), imageId);
        listaProgramiPocetnici = (ListView) findViewById(R.id.listaProgramiPocetnici);
        listaProgramiPocetnici.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        listaProgramiPocetnici.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                if (position == 0) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningZaCijeloTijelo.class);
                    startActivity(intent);
                } else if (position == 1) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningZaGornjiDonjiDioTijela.class);
                    startActivity(intent);
                } else if (position == 2) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningKodKuceBezUtega.class);
                    startActivity(intent);
                } else if (position == 3){
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreningaTreningKodKuceBezUtega2.class);
                    startActivity(intent);
                } else if (position == 4){
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreningaTreningKodKuceBezUtega3.class);
                    startActivity(intent);
                } else if (position == 5) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningKodKucePocetnicki.class);
                    startActivity(intent);
                } else if (position == 6) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningKodKuceSrednji.class);
                    startActivity(intent);
                } else if (position == 7) {
                    Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuildingTreningKodKuceNapredni.class);
                    startActivity(intent);
                }


                    AdapterListaVjezbe adapter = new AdapterListaVjezbe(ListaProgramiBodybuilding.this, getResources().getStringArray(R.array.programi_srednje_napredni), imageId2);
                    listaProgramiSrednji = (ListView) findViewById(R.id.listaProgramiSrednji);
                    listaProgramiSrednji.setAdapter(adapter);
                    adapter.notifyDataSetChanged();
                    listaProgramiSrednji.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                            if (position == 0){
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreninga3dana.class);
                                startActivity(intent);
                        } else if (position == 1){
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreninga4dana.class);
                            startActivity(intent);
                        } else if(position == 2){
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreninga5dana.class);
                            startActivity(intent);
                        } else if (position == 3) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiBodybuilding3plus1.class);
                            startActivity(intent);
                        } else if (position == 4) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiPowerBBPHAT.class);
                            startActivity(intent);
                        } else if (position == 5) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaPrsa.class);
                            startActivity(intent);
                        } else if (position == 6) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaLedja.class);
                            startActivity(intent);
                        } else if (position == 7) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaRamena.class);
                            startActivity(intent);
                        } else if (position == 8) {
                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaRuke.class);
                            startActivity(intent);
                        } else if (position == 9) {
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaNoge.class);
                                startActivity(intent);
                            } else if(position == 10) {
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaZaTrbuh.class);
                                startActivity(intent);
                            }else if (position == 11){
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiSpecijalizacijaZaListove.class);
                                startActivity(intent);
                            } else if (position == 12) {
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreningaPushPullLegs.class);
                                startActivity(intent);
                            } else if (position == 13) { //UREDI
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreningaPushPullLegs.class);
                                startActivity(intent);
                            } else if (position == 14) { // UREDI
                                Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiTreningaPushPullLegs.class);
                                startActivity(intent);
                            }




                                AdapterListaVjezbe adapter = new AdapterListaVjezbe(ListaProgramiBodybuilding.this, getResources().getStringArray(R.array.programi_napredni), imageId3);
                                listaProgramiNapredni = (ListView) findViewById(R.id.listaProgramiNapredni);
                                listaProgramiNapredni.setAdapter(adapter);
                                adapter.notifyDataSetChanged();
                                listaProgramiNapredni.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                    @Override
                                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                                        if (position == 0) {
                                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiKreacijaVlastitogMisicnaVlakna.class);
                                            startActivity(intent);
                                        } else if (position == 1) {
                                            Intent intent = new Intent(ListaProgramiBodybuilding.this, ProgramiKreacijaVlastitogPrimjeriTreninga.class);
                                            startActivity(intent);
                                        }
                                    }
                                });
                        }});}});}

我在那里错过了什么? 试图在互联网上遵循各种教程,但没有一个按照我想要的方式工作。

0 个答案:

没有答案