1
내 활동에서 하나의 버튼이 있는데, 버튼을 클릭하면 해당 버튼의 제목이 & ListView
인 사용자 정의 대화 상자가 표시됩니다. Android : getView가 사용자 정의 어댑터에서 호출되지 않았습니다.
ListView
에 대한 어댑터를 설정하지만 배열을 called.my하지
getView()
방법은
ArrayList<String>
&의 크기는 다음 3
을 내 코드입니다. Activity.java에서
::
notification_btn = (Button) findViewById(R.id.notifications_btn);
notification_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Dialog dialog = new Dialog(Home.this,android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.notifications_layout);
ListView list = (ListView) dialog.findViewById(R.id.listView_notifications);
TextView title = (TextView) dialog.findViewById(R.id.dialogTitle);
TextView footer = (TextView) dialog.findViewById(R.id.notification_footer);
title.setText("Title");
NotificationAdapter adapter = new NotificationAdapter(Home.this,array);
list.setAdapter(adapter);
dialog.show();
}
});
NotificationAdapter.java :: 왜 getView()
방법
public class NotificationAdapter extends BaseAdapter{
ArrayList<String> items;
private Context context;
private LayoutInflater mInflater;
static class ViewHolder {
TextView text;
}
public NotificationAdapter(Context context, ArrayList<String> items) {
this.context = context;
this.items = items;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return items.size();
}
@Override
public Object getItem(int arg0) {
return items.get(arg0);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) { // if it's not recycled, initialize some
// attributes
convertView = mInflater.inflate(R.layout.notifiation_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text_notification);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
holder.text.setText(items.get(position));
} catch (Exception e) {
VLogger.getLogger().info("Exception occured :: "+e);
}
return convertView;
}
}
라고하지? 이유를 찾지 못했습니다. 도와주세요.
검사 항목의 크기 :
당신은 그래서 목록을 채울 것입니다 설정 변경된 데이터에 대한 어댑터를 통지해야 , 크기가 0이면 getview 메서드가 호출되지 않습니다. –
어댑터의'getView()'는 ** @ Override **입니까? – user370305
1.6 jdk부터 @Override는 필수가 아닙니다. –