1
我在android系統
此使用ExpandableListView是getChildView在適配器類代碼:
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.childrow, null);
holder = new ViewHolder();
holder.tv = (TextView) convertView
.findViewById(R.id.textView1);
// I added this line of code
holder.stop = (Button) convertView.findViewById(R.id.button3);
holder.position = groupPosition;
convertView.setTag(holder);
holder.stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ViewHolder holder = new ViewHolder();
holder = (ViewHolder) v.getTag();
int position = 0;
position = holder.position; ************* here
System.out.println("coolapse tag " + position);
expList.collapseGroup(position);
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
它給NullPointerException異常的線上標有** 有什麼問題?
這是一類 \t靜態類ViewHolder { \t \t \t \t按鈕停止; \t \t TextView tv; \t \t int position; \t} – Developer 2012-04-08 18:16:45
您不能使用靜態類,每個視圖需要一個持有者實例。 – dmon 2012-04-08 18:22:55
所以我應該用什麼? – Developer 2012-04-08 18:25:59