The first item of the listView does not display as it is supposed to like the rest two, but when clicked on the first item and then directed to the next page the whole content is display.
Screenshot
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" />
Your first item is ok. He just behind actionBar
try change main
LinearLayout
to
RelativeLayout
to appBarLayout add id field and to listview add
android:layout_below="@+id/appBarLayoutId"
after all should be fine.
or add to listview
topMargin = ?attr/actionBarSize"