Java 列表视图不显示
我尝试显示listview,但无法解决此问题。请更正我的密码。 这个项目是在android studio中制作的。我在android studio中制作了第一个应用程序。 我不知道我的源代码中有什么Java 列表视图不显示,java,android,Java,Android,我尝试显示listview,但无法解决此问题。请更正我的密码。 这个项目是在android studio中制作的。我在android studio中制作了第一个应用程序。 我不知道我的源代码中有什么 这是我的代码: 适配器类: 公共类ProjectListAdapter扩展了BaseAdapter{ public Context mContext; int mResource; private static ArrayList<DataMyProject> listaProjekto
这是我的代码: 适配器类: 公共类ProjectListAdapter扩展了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;
公共上下文mContext;
国际资源;
私有静态数组列表listaProjektow;
拉平机;
公共项目列表适配器(上下文、ArrayList对象){
listaProjektow=对象;
mInflater=LayoutInflater.from(上下文);
}
@凌驾
public int getCount(){
返回0;
}
@凌驾
公共对象getItem(int i){
返回null;
}
@凌驾
公共长getItemId(int i){
返回0;
}
@非空
@凌驾
公共视图getView(int位置,@Nullable视图convertView,@NonNull视图组父级){
int lpProjektu=listaProjektow.get(position.getLp_projektu();
字符串nazwaProjektu=listaProjektow.get(position.getNazwaProjektu();
字符串statusProjektu=listaProjektow.get(position.getStatusProjektu();
字符串dataStart=listaProjektow.get(position.getDataStart();
字符串dataKoniec=listaProjektow.get(position.getDataKoniec();
DataMyProject daneProjektu=新的DataMyProject(lpProjektu、nazwaProjektu、statusProjektu、dataStart、dataKoniec);
LayoutFlater充气机=LayoutFlater.from(mContext);
convertView=充气机。充气(mResource,父项,false);
convertView=充气机.充气(R.layout.adapter\u view\u layout\u项目,空);
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);
text statusProjektu.setText(statusProjektu);
setText(dataStart);
textViewDataKoniec.setText(dataKoniec);
返回视图;
我的专题课:
公共类MyProjects扩展了片段{
@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;
}
@Nullable
@凌驾
创建视图时的公共视图(@NonNull LayoutInflater inflater、@Nullable ViewGroup container、@Nullable Bundle savedInstanceState){
View widok=充气机。充气(R.layout.my_项目,容器,false);
ArrayList listaProjektow=新的ArrayList();
新增(新的DataMyProject(0,“Nazwa”,“jakis”,“2017-02-02”,“2017-04-04”);
新增(新数据MyProject(1,“Taki”,“+”,“2018-05-05”,“2018-09-01”);
ListView listViewListaProjektow=(ListView)widok.findViewById(R.id.listViewProjekty);
//ProjectListAdapter=new ProjectListAdapter(this,R.layout.my_projects,listaProjektow);
setAdapter(新项目列表适配器(getActivity(),listaProjektow));
返回widok;
}
您需要在getCount()
中返回listaProjektow.size();
而且,您不希望listaProjektow
是静态的return listaProjektow.size>。您能展示我的代码是如何做到这一点的吗?用return listaprojectListAdapter
的getCount()
方法替换中的返回0;
。我删除这一行并返回listaProjektow.size(),但当我运行应用程序show communique“application stop”时,将textLp.setText(lpProjektu);
更改为textLp.setText(Integer.toString(lpProjektu));
。如果它仍然崩溃,您需要查看以确定崩溃的原因。