void showDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.title)
.setAdapter(new DemoAdapter(this), new onClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
//todo
}
}).show();
}
private class DemoAdapter extends BaseAdapter{
LayoutInflater layInflater;
ShareAdapter(Context context) {
layInlater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return 2;//item个数
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = layoutInflater.inflate(R.layout.layout_share_item,(注释: layout 布局) parent, false);
}
TextView textView = (TextView)convertView.findViewById(R.id.share_title);
textView.setText(SHARE_TEXT[position]);注释:textText设值
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(SHARE_ICON[position], 0, 0, 0); 注释:设图片
return convertView;
}
}