Java Android studio listview没有';不显示

Java Android studio listview没有';不显示,java,android,listview,Java,Android,Listview,你好,我是新来安卓工作室的,我可能犯了一个我找不到的愚蠢的错误。 因此,基本上我已经做了一个所有天的选项卡式活动,我想做一个列表(我想做一个定制的时间表应用程序,它将包含我每天做的所有活动)。我的ListView没有显示:(.我做错了什么 编辑活动类别代码: 包com.timemanagement.restrictedpower.timemanagement; 导入android.os.Bundle; 导入android.support.v4.app.Fragment; 导入android.su

你好,我是新来安卓工作室的,我可能犯了一个我找不到的愚蠢的错误。 因此,基本上我已经做了一个所有天的选项卡式活动,我想做一个列表(我想做一个定制的时间表应用程序,它将包含我每天做的所有活动)。我的ListView没有显示:(.我做错了什么

编辑活动类别代码:

包com.timemanagement.restrictedpower.timemanagement;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.support.v4.app.FragmentManager;
导入android.support.v4.app.FragmentPagerAdapter;
导入android.support.v4.view.ViewPager;
导入android.support.v7.app.AppActivity;
导入android.support.v7.widget.Toolbar;
导入android.view.Gravity;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
导入android.widget.TextView;
导入java.util.ArrayList;
导入java.util.List;
公共类EditActivity扩展了AppCompatActivity{
私人部门SPAGERAAdapter MSECTIONSPAGERAAdapter;
私有视图寻呼机mViewPager;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
Toolbar Toolbar=(Toolbar)findViewById(R.id.Toolbar);
设置支持操作栏(工具栏);
mSectionsPagerAdapter=newsectionspageradapter(getSupportFragmentManager());
mViewPager=(ViewPager)findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.menu\u编辑,菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
/**
*包含简单视图的占位符片段。
*/
公共静态字符串日(int-id){
开关(id){
案例1:
返回“星期一”;
案例2:
返回“星期二”;
案例3:
返回“星期三”;
案例4:
返回“星期三”;
案例5:
返回“星期五”;
案例6:
返回“星期六”;
案例7:
返回“星期日”;
}
返回null;
}
公共静态类占位符片段扩展了片段{
私有静态最终字符串ARG\u SECTION\u NUMBER=“SECTION\u NUMBER”;
公共占位符片段(){
}
公共静态占位符片段newInstance(int sectionNumber){
占位符片段=新占位符片段();
Bundle args=新Bundle();
参数Putin(参数段号,段号);
fragment.setArguments(args);
返回片段;
}
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图v=充气机。充气(R.layout.fragment\u编辑,容器,错误);
ListView lv=(ListView)v.findViewById(R.id.Activities);
List水果_List=new ArrayList();
水果列表。添加(“苹果”);
水果清单。添加(“草莓”);
ArrayAdapter ArrayAdapter=新的ArrayAdapter(getContext(),android.R.layout.simple\u list\u item\u 1,fruits\u list);
低压设置适配器(阵列适配器);
lv.invalidateViews();
视图根视图=充气机。充气(R.layout.fragment\u编辑,容器,false);
TextView TextView=(TextView)rootView.findViewById(R.id.Day);
int id=getArguments().getInt(ARG\u节号);
字符串day=day(getArguments().getInt(ARG_SECTION_NUMBER));
textView.setText(天);
textView.setGravity(重力.重心垂直|重力.重心水平);
返回rootView;
}
}
公共类节SpagerAdapter扩展了FragmentPagerAdapter{
公共部分SpagerAdapter(碎片管理器fm){
超级(fm);
}
@凌驾
公共片段getItem(int位置){
返回PlaceholderFragment.newInstance(位置+1);
}
@凌驾
public int getCount(){
//显示共3页。
返回7;
}
@凌驾
公共字符序列getPageTitle(int位置){
开关(位置){
案例0:
返回“第1节”;
案例1:
返回“第2节”;
案例2:
返回“第3节”;
案例3:
返回“第4节”;
案例4:
返回“第5节”;
案例5:
返回“第6节”;
案例6:
返回“第7节”;
}
返回null;
}
}
}
Xml代码:


我已经解决了您的问题,您必须更改线性布局的高度,因为它在应用应用应用程序栏布局时是隐藏的。您的列表视图应该放在应用程序栏布局下方。我已经更改了android:layout\u height=“300dp”, android:layout\u marginTop=“100dp”在线性布局中。现在,您的列表视图显示在
package com.timemanagement.restrictedpower.timemanagement;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class EditActivity extends AppCompatActivity {
    private SectionsPagerAdapter mSectionsPagerAdapter;
    private  ViewPager mViewPager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
        mViewPager = (ViewPager) findViewById(R.id.container);
        mViewPager.setAdapter(mSectionsPagerAdapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_edit, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static String day(int id){
        switch (id) {
            case 1:
                return "Monday";
            case 2:
                return "Tuesday";
            case 3:
                return "Wednesday";
            case 4:
                return "Thirsday";
            case 5:
                return "Friday";
            case 6:
                return "Saturday";
            case 7:
                return "Sunday";
        }
        return null;
    }
    public static class PlaceholderFragment extends Fragment {
        private static final String ARG_SECTION_NUMBER = "section_number";

        public PlaceholderFragment() {
        }
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.fragment_edit, container, false);

            ListView lv = (ListView) v.findViewById(R.id.Activities);
            List<String> fruits_list = new ArrayList<String>();
            fruits_list.add("Apple");
            fruits_list.add("Strawberry");
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, fruits_list);
            lv.setAdapter(arrayAdapter);
            lv.invalidateViews();
            View rootView = inflater.inflate(R.layout.fragment_edit, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.Day);
            int id = getArguments().getInt(ARG_SECTION_NUMBER);
            String day = day(getArguments().getInt(ARG_SECTION_NUMBER));
            textView.setText(day);
            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
            return rootView;
        }
    }
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 7;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "SECTION 1";
                case 1:
                    return "SECTION 2";
                case 2:
                    return "SECTION 3";
                case 3:
                    return "SECTION 4";
                case 4:
                    return "SECTION 5";
                case 5:
                    return "SECTION 6";
                case 6:
                    return "SECTION 7";
            }
            return null;
        }
    }
}
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1234">

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

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/Activities"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        style="@android:style/Widget.DeviceDefault.ExpandableListView" />
</LinearLayout>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="60dp"
    android:layout_width="match_parent">

    <TextView
        android:text="TextView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="5mm"
        android:id="@+id/Day" />

    <TextView
        android:id="@+id/section_label"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:textColor="#FFCC91"
        android:textSize="6mm"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1234">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginTop="100dp"
    android:layout_weight="1">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/Activities"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        style="@android:style/Widget.DeviceDefault.ExpandableListView" />
</LinearLayout>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="60dp"
    android:layout_width="match_parent">

    <TextView
        android:text="TextView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="5mm"
        android:id="@+id/Day" />

    <TextView
        android:id="@+id/section_label"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:textColor="#FFCC91"
        android:textSize="6mm"
        android:gravity="center"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</android.support.design.widget.AppBarLayout>