我试图通过扩展baseAdapter来实现支持整数Arraylists的listAdapter,当初始化我的应用程序崩溃的活动时。因为即时通讯新手我想知道是否有人可以发现我的实现错误
package com.test.testapp;
import java.util.ArrayList;
import com.test.testapp.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class myListAdapterIntegers extends BaseAdapter {
ArrayList<Integer> arrayIntList = new ArrayList<Integer>();
Context context;
myListAdapterIntegers(Context c, ArrayList<Integer> myListAdapterIntegers) {
this.arrayIntList = myListAdapterIntegers;
this.context = c;
}
@Override
public int getCount() {
return arrayIntList.size();
}
@Override
public Object getItem(int location) {
return arrayIntList.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = View.inflate(context, R.layout.entry_row_int, null);
int value = arrayIntList.get(position);
TextView monthTextView = (TextView) v.findViewById(R.id.text_row_int);
monthTextView.setText(value);
return v;
}
}
答案 0 :(得分:1)
您正在使用整数值调用setText()
。 Android会将此解释为字符串资源ID。如果您希望它以数字形式显示在列表中,请使用setText(String.valueOf(value));