listView 的第一项未从自定义适配器的布局文件中加载完整数据,但其余项工作正常

First item of the listView is not loaded full data from the custom adapter's layout file but the rest are working just fine

listView 的第一个项目没有显示,因为它应该像其余两个一样,但是当单击第一个项目然后定向到下一页时,会显示整个内容。

截图

This is the activity where list is to be loaded

public class FacultyViewNoticeActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

private ListView listView;
private DatabaseReference reference;
private List<Notice> noticesList;
private FacultyViewNoticeAdapter assAdapter;
private ProgressDialog pDialog;

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

    declarations();
    loadNoticeList();

    listView.setOnItemClickListener(this);
}

private void declarations() {
    listView = (ListView) findViewById(R.id.listViewNotice_FacultyViewNoticeActivity);
    reference = FirebaseDatabase.getInstance().getReference();
    noticesList = new ArrayList<>();
    pDialog = new ProgressDialog(FacultyViewNoticeActivity.this);
}

private void loadNoticeList() {
    pDialog.setTitle("Searching...");
    pDialog.show();
    reference.child("notice").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            noticesList.clear();
            for (DataSnapshot ps : dataSnapshot.getChildren()) {
                Notice n = ps.getValue(Notice.class);
                Log.i("CollegeDiary", "Notice = " + n.getNotice() + "\nTitle = " + n.getTitle());
                noticesList.add(n);
            }
            assAdapter = new FacultyViewNoticeAdapter(FacultyViewNoticeActivity.this, noticesList);
            listView.setAdapter(assAdapter);
            pDialog.dismiss();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            pDialog.dismiss();
        }

    });
}

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    Notice a = noticesList.get(i);
    Intent intent = new Intent(FacultyViewNoticeActivity.this, FacultyViewNoticeDetailsActivity.class);
    intent.putExtra("Data", a);
    startActivity(intent);
}

}

activity_faculty_view_notice.xml file

<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"
android:orientation="vertical"
tools:context="com.collegecoder.collegediary.activity.FacultyViewNoticeActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_FacultyViewNoticeActivity"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

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

<ListView
    android:id="@+id/listViewNotice_FacultyViewNoticeActivity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

This is the adapter for it

public class FacultyViewNoticeAdapter extends ArrayAdapter {
private Activity context;
private List<Notice> noticeList;
private static int x = 0;

public FacultyViewNoticeAdapter(Activity context, List<Notice> noticeList) {
    super(context, R.layout.layout_view_notices, noticeList);
    this.context = context;
    this.noticeList = noticeList;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View listViewItem = inflater.inflate(R.layout.layout_view_notices, parent, false);

    TextView title = listViewItem.findViewById(R.id.title_layout_view_notices);
    TextView date = listViewItem.findViewById(R.id.date_layout_view_notices);
    TextView notice = listViewItem.findViewById(R.id.notice_layout_view_notices);

    Notice noticeUpload = noticeList.get(position);

    if (noticeUpload != null) {
        Log.i("CollegeDiary", String.valueOf(x));
        title.setText(noticeUpload.getTitle());
        notice.setText(noticeUpload.getNotice());
        date.setText(noticeUpload.getD() + "-" + noticeUpload.getM() + "-" + noticeUpload.getY());
        Log.i("CollegeDiary", "ADAPTER = " + title.getText().toString() + "\n" + notice.getText().toString() + "\n" + date.getText().toString());
        x++;
    } else {
        Log.i("CollegeDiary", "null");
    }
    return listViewItem;
}

}

layout_view_notices.xml file

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">

<TextView
    android:id="@+id/title_layout_view_notices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="totle"
    android:textAlignment="center"
    android:textColor="@android:color/black"
    android:textSize="20sp" />

<TextView
    android:id="@+id/date_layout_view_notices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Date" />

<TextView
    android:id="@+id/notice_layout_view_notices"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxLines="1"
    android:text="description"
    android:textSize="16sp" />

您的第一项没问题。他就在 actionBar

后面

尝试改变主

LinearLayout

RelativeLayout

给appBarLayout添加id字段 并在列表视图中添加

android:layout_below="@+id/appBarLayoutId"

毕竟应该没问题。

或添加到列表视图

topMargin = ?attr/actionBarSize"