1

我写了以下代码:

TodosOverviewActivity extends ListActivity{

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.todo_list);
            this.getListView().setDividerHeight(2);
            registerForContextMenu(getListView());
            fillData();
        }



    private void fillData() {

    fetchEvents();

     adapter2 = new MySimpleArrayAdapter
                (this, nameOfEvent, startDates, descriptions);
     setListAdapter(adapter2);
            }

public class MySimpleArrayAdapter extends ArrayAdapter<String> {

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

        LayoutInflater inflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View rowView = inflater.inflate(R.layout.todo_list, parent, false);

        TextView titleTextView = (TextView) rowView
                .findViewById(R.id.todo_row_title);
        TextView dateTextView = (TextView) rowView
                .findViewById(R.id.todo_row_date);
        ImageView imageView = (ImageView) rowView
                .findViewById(R.id.todo_row_image);

            titleTextView.setText(mTitles[position]);

    ..

    }

但是它在 nullpointer 上失败titleTextView。我错过了什么?

4

2 回答 2

2

改变这个 - 在getView()

View rowView = inflater.inflate(R.layout.todo_list, parent, false);

至:

View rowView = inflater.inflate(R.layout.todo_row, parent, false);

为了您的代码,我希望fillData()该方法fetchEvents();不会触发 UI 线程上的网络 :)

于 2013-09-26T14:29:59.933 回答
1

尝试:

View rowView = inflater.inflate(R.layout.todo_list, null);

并且不要忘记rowView在函数结束时返回。

于 2013-09-26T14:19:26.587 回答