我似乎无法让我的listView for android工作

时间:2013-07-16 04:17:15

标签: java android listview android-arrayadapter

我正在和一本书(大书呆子牧场指南,Android)一起工作,我正在努力让listView正常工作。它曾经工作过,我不相信我已经改变了任何代码,但是当我运行我的应用程序时,它只显示一个空白页面。就像我之前说的那样,之前我确实有一个listView完全工作,使用相同的代码。这是我的主要代码:

//如果您希望看到任何其他类或文件,请发表评论,我可以添加代码。

public class CrimeListFragment extends ListFragment {

    private static final String Test = "CrimeListFragment";
    private ArrayList<Crime> mCrimes;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getActivity().setTitle(R.string.crimes_title);

        mCrimes = CrimeLab.get(getActivity()).getCrimes();
        CrimeAdapter adapter = new CrimeAdapter(mCrimes);
        setListAdapter(adapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        Crime c = ((CrimeAdapter)getListAdapter()).getItem(position);
        Intent i = new Intent(getActivity(), CrimeActivity.class);
        startActivity(i);
    }

    private class CrimeAdapter extends ArrayAdapter<Crime> {

        public CrimeAdapter(ArrayList<Crime> crimes) {
            super(getActivity(), 0, crimes);    
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = getActivity().getLayoutInflater().inflate(R.layout.list_item_crime, null);
            }

            Crime c = getItem(position);

            TextView titleTextView = (TextView)convertView.findViewById(R.id.crime_list_item_titleTextView);
            titleTextView.setText(c.getTitle());
            TextView dateTextView = (TextView)convertView.findViewById(R.id.crime_list_item_dateTextView);
            dateTextView.setText(c.returnDate());
            CheckBox solvedCheckBox = (CheckBox)convertView.findViewById(R.id.crime_list_item_solvedCheckBox);
            solvedCheckBox.setChecked(c.isSolved());

            return convertView;
        }
    }
}

非常感谢任何帮助。这个问题已经持续了几个星期,非常令人沮丧。谢谢大家!

0 个答案:

没有答案