android listview没有显示项目

时间:2014-07-06 08:25:01

标签: android sql-server listview

我有一个带有ORMLite数据库的应用程序,它可以与服务器连接并更新表的数据。这是正确的,但我有一个listview是项目更新,但一旦他们更新我看不到他们...我的意思是,他们在那里,因为如果我点击它的工作,并做它必须做的事情,但是看不到列表中项目的任何文本(标题)... 虽然黑色是默认文本颜色,并且在从服务器更新数据之前可以看到项目,我试图将textColor设置为黑色,只是尝试一些东西,但它没有工作... 有什么想法吗?

包含一些数据和列表的片段的一些代码:

 @Override
 public void onViewCreated(View view, Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onViewCreated(view, savedInstanceState);

    Intent intent = getActivity().getIntent();
    mCentre = intent.getParcelableExtra(ARG_CENTRE);

    mNomCentreTextView = (TextView) view
            .findViewById(R.id.nomCentreTextView);
    mTelefonCentreTextView = (TextView) view
            .findViewById(R.id.telefonCentreTextView);
    mDireccioCentreTextView = (TextView) view
            .findViewById(R.id.direccioCentreTextView);
    mTitularitatCentreTextView = (TextView) view
            .findViewById(R.id.titularitatCentreTextView);

    try {
        UtilDAOImpl dao = new UtilDAOImpl(getActivity());
        llistaEstudis = dao.lookupEstudisForCentre(mCentre);
        nomEstudis = new ArrayList<String>();
        for (Estudi estudi : llistaEstudis) {
            nomEstudis.add(estudi.getNom());
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    adapter = new ArrayAdapter<String>(view.getContext(),
            R.layout.centre_list_row_two, R.id.centre_row, nomEstudis) {
    String nomEstudi = "";


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            UtilDAOImpl dao = new UtilDAOImpl(getActivity());
            Estudi estudi = null;
            try {
                estudi = dao.lookupEstudiByName(nomEstudis.get(position));
                Log.d(TAG, "nom estudi -> " + nomEstudis.get(position));
                if(estudi.getTipus().equals("1")){
                    if(estudi.getSuperiorMitja().equals("superior")){
                        nomEstudi = "GS " + " " + estudi.getNom();
                    }else if(estudi.getSuperiorMitja().equals("mitja")){
                        nomEstudi = "GM " + " " + estudi.getNom();
                    }
                }else if(estudi.getTipus().equals("2")){
                    nomEstudi = "PFI " + " " + estudi.getNom();
                }else{
                    nomEstudi = "FO " + " " + estudi.getNom();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }

            View view = super.getView(position, convertView, parent);
            TextView text1 = (TextView) view.findViewById(R.id.centre_row);
            text1.setPadding(0, 5, 0, 5);
            text1.setText(nomEstudi);
            text1.setTextColor(Color.BLACK);
            return view;
        }
    };
    mNomCentreTextView.setText(mCentre.getNom());
    telefon = mCentre.getTelefon();
    if(telefon.equals("")){
        telefon = getResources().getString(R.string.no_telefon);
    }else{
        mTelefonCentreTextView.setText(telefon);
    }
    direccio = mCentre.getDireccio();
    if(direccio == null){
        direccio = getResources().getString(R.string.no_direccio);
    }else{
        mDireccioCentreTextView.setText(mCentre.getDireccio());
    }

    String titularitat = mCentre.getTitularitat();
    if(titularitat == null){
        titularitat = getResources().getString(R.string.no_titularitat);
    }else{
        if (titularitat.equals("0")) {
            titularitat = getResources().getString(R.string.public_);
        } else if(titularitat.equals("1")){
            titularitat = getResources().getString(R.string.concertat);
        }else if(titularitat.equals("2")){
            titularitat = getResources().getString(R.string.privat);
        }
    }
    mTitularitatCentreTextView.setText(titularitat);

    setListAdapter(adapter);
    getListView().setOnItemClickListener(this);
}

0 个答案:

没有答案