wyswietlanie listview w android studio

0

Witam mam mały problem . Nie wiem czemu ale nie wyswietla mi się listView . Czy mógłby ktoś pomoc ?
Oto kawałek kodu :

public class MyProjects extends Fragment {

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View widok = inflater.inflate(R.layout.my_projects, container, false);
    ArrayList<DataMyProject> listaProjektow = new ArrayList<>();
    listaProjektow.add(new DataMyProject(0, "Nazwa", "jakis", "2017-02-02,", "2017-04-04"));
    listaProjektow.add(new DataMyProject(1, "Taki", "+", "2018-05-05", "2018-09-01"));



    ListView listViewListaProjektow = (ListView) widok.findViewById(R.id.listViewProjekty);



   // ProjectListAdapter adapter = new ProjectListAdapter(this, R.layout.my_projects, listaProjektow);
    listViewListaProjektow.setAdapter(new ProjectListAdapter(getActivity(), listaProjektow));
    
    return widok;
}

public class ProjectListAdapter extends BaseAdapter{

public Context mContext;
int mResource;
private static ArrayList<DataMyProject> listaProjektow;
LayoutInflater mInflater;

public ProjectListAdapter(Context context,  ArrayList<DataMyProject> objects) {

    listaProjektow = objects;
    mInflater = LayoutInflater.from(context);
}


@Override
public int getCount() {
    return 0;
}

@Override
public Object getItem(int i) {
    return null;
}

@Override
public long getItemId(int i) {
    return 0;
}

@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {


    int lpProjektu = listaProjektow.get(position).getLp_projektu();
    String nazwaProjektu = listaProjektow.get(position).getNazwaProjektu();
    String statusProjektu = listaProjektow.get(position).getStatusProjektu();
    String dataStart = listaProjektow.get(position).getDataStart();
    String dataKoniec = listaProjektow.get(position).getDataKoniec();


    DataMyProject daneProjektu = new DataMyProject(lpProjektu, nazwaProjektu, statusProjektu, dataStart, dataKoniec);

    LayoutInflater inflater = LayoutInflater.from(mContext);
    convertView = inflater.inflate(mResource, parent, false);
    convertView = inflater.inflate(R.layout.adapter_view_layout_project, null);

    TextView textLp = (TextView) convertView.findViewById(R.id.textViewLp);
    TextView textNazwaProjektu = (TextView) convertView.findViewById(R.id.textViewNazwaProjektu);
    TextView textStatusProjektu = (TextView) convertView.findViewById(R.id.textViewStatus);
    TextView textDataStart = (TextView) convertView.findViewById(R.id.textViewDataStart);
    TextView textViewDataKoniec = (TextView) convertView.findViewById(R.id.textViewDataKoniec);

    textLp.setText(lpProjektu);
    textNazwaProjektu.setText(nazwaProjektu);
    textStatusProjektu.setText(statusProjektu);
    textDataStart.setText(dataStart);
    textViewDataKoniec.setText(dataKoniec);


    return convertView;
0

Przeczytaj jakiś normalny tutorial, bo Twój adapter to straszny bałagan. Jakieś w ogóle nieużywane pola. Statyczna lista ustawiana w konstruktorze. Bezsensowne nadpisywanie metod. Tutaj masz link do pierwszego z brzegu.

Pierwszy problem. Informujesz adapter, że nie ma żadnych elementów do wyświetlenia.

@Override
public int getCount() {
    return 0;
}

Drugi, to z głowy nie wiem nawet jak to niżej się zachowa. Wydaje mi się, że pierwsza linijka może wywalić program. Druga może niepoprawnie stworzyć widok dla listy. Obie w połączeniu są w ogóle bezsensowne, bo ta pierwsza nawet nie ma wpływu na dalszą część programu.

convertView = inflater.inflate(mResource, parent, false);
convertView = inflater.inflate(R.layout.adapter_view_layout_project, null);

1 użytkowników online, w tym zalogowanych: 0, gości: 1