android listview行号删除零

时间:2014-10-12 12:23:37

标签: android listview numbers row

我有列表视图来显示标题,我需要在我的getView中添加行号。我的代码工作正常但我的列表视图泊松从零开始(0),我该如何禁用它?

  @Override
    public View getView(int position, View convertView, ViewGroup parent){
        View rowView;
        if(convertView == null) {
            rowView = getActivity().getLayoutInflater().inflate(R.layout.searchitemview, null);
        } else {
            rowView = convertView;
        }

        TextView firstTextView = (TextView) rowView.findViewById(R.id.txtTitle);
        firstTextView.setText(items.get(position).first);   

        TextView number = (TextView) rowView.findViewById(R.id.number);
        number.setText(""+position);

        TextView thirdTextView = (TextView) rowView.findViewById(R.id.txtSize);
        if(items.get(position).fourth != "00:00" || items.get(position).fourth != ""){
            thirdTextView.setText("Duration: " + items.get(position).fourth);
        }else{
            thirdTextView.setVisibility(View.GONE);
        }

        return rowView;
    }
}   

此代码从零(0)开始行号我希望我的列表视图行号从一(1)开始

1 个答案:

答案 0 :(得分:0)

索引默认从0开始,自己增加:

number.setText(String.valueOf(position+1));