0
조각에 부풀어 오르는 사용자 지정 목록 어댑터가 있고 해당 조각이 활동에 포함되어 있습니다. 이미지의 클릭을 처리하는 인터페이스를 구현하고 싶습니다. 그 활동 클래스 어댑터 ..하지만 널 포인터 예외를 받고 메신저 .. 여기 내 코드입니다 :
에 포함 된 활동에 대한 사용자 정의 목록 어댑터와 상호 작용
이 내 사용자 정의 어댑터 클래스의 일부입니다
public ActionSelection mCallBack;
public interface ActionSelection {
public void onActionSelected(int position);
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
LayoutInflater inflater = (LayoutInflater) getContext().
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.main_list_item, null);
// Obtain current mainListItem using position
MainListItem item = mainListItems.get(position);
// Set the custom view
if (item != null) {
((SmartImageView) view.findViewById(R.id.imageview_mainlist_profile_picture)).
setImageUrl(item.getProfile_picture());
((TextView) view.findViewById(R.id.textview_mainlist_fullname)).
setText(item.getFullname());
((TextView) view.findViewById(R.id.textview_mainlist_username)).
setText(item.getUsername());
((ImageView) view.findViewById(R.id.imageview_mainlist_action)).
setImageResource(item.getAction());
ImageView action = (ImageView) (view.findViewById(R.id.imageview_mainlist_action));
action.setId(position);
action.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mCallBack.onActionSelected(5);
}
});
}
내 MainActivity i에서 다음 공동과 인터페이스를 구현 드 :
@Override
public void onActionSelected(int position) {
Log.v("test", String.valueOf(position));
}
로그 출력 게시! NPE는 어디서 구할 수 있습니까? 이 문장의 – SimonSays
: mCallBack.onActionSelected (5); –
필요한 모든 정보가 있습니다. 분명히 mCallBack은 null이므로 NPE입니다. 변수를 Object로 설정하지 않았거나 명시 적으로 null로 설정 한 경우 변수가 null입니다. –