我有一个添加按钮,通过单击该添加按钮会弹出一个列表视图,并且在该列表视图的每一行中都有一个按钮。通过单击特定行的按钮(我的意思是该行的文本和图像)应该作为图像按钮添加到我的应用程序的主屏幕。
这是 listView 的 customadapter 类
public class NewsRowAdapter extends ArrayAdapter<Item> {
private Activity activity;
private List<Item> items;
private Item objBean;
private int row;
private DisplayImageOptions options;
ImageLoader imageLoader;
public NewsRowAdapter(Activity act, int resource, List<Item> arrayList) {
super(act, resource, arrayList);
this.activity = act;
this.row = resource;
this.items = arrayList;
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.profile)
.showImageForEmptyUrl(R.drawable.profile).cacheInMemory()
.cacheOnDisc().build();
imageLoader = ImageLoader.getInstance();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(row, null);
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if ((items == null) || ((position + 1) > items.size()))
return view;
objBean = items.get(position);
holder.tvTitle = (TextView) view.findViewById(R.id.tvtitle);
holder.tvDesc = (TextView) view.findViewById(R.id.tvdesc);
holder.tvDate = (TextView) view.findViewById(R.id.tvdate);
holder.imgView = (ImageView) view.findViewById(R.id.image);
holder.pbar = (ProgressBar) view.findViewById(R.id.pbar);
holder.button = (Button) view.findViewById(R.id.button);
if (holder.tvTitle != null && null != objBean.getTitle()
&& objBean.getTitle().trim().length() > 0) {
holder.tvTitle.setText(Html.fromHtml(objBean.getTitle()));
}
if (holder.tvDesc != null && null != objBean.getDesc()
&& objBean.getDesc().trim().length() > 0) {
holder.tvDesc.setText(Html.fromHtml(objBean.getDesc()));
}
if (holder.tvDate != null && null != objBean.getPubdate()
&& objBean.getPubdate().trim().length() > 0) {
holder.tvDate.setText(Html.fromHtml(objBean.getPubdate()));
}
if (holder.imgView != null) {
if (null != objBean.getLink()
&& objBean.getLink().trim().length() > 0) {
final ProgressBar pbar = holder.pbar;
imageLoader.init(ImageLoaderConfiguration
.createDefault(activity));
imageLoader.displayImage(objBean.getLink(), holder.imgView,
options, new ImageLoadingListener() {
@Override
public void onLoadingComplete() {
pbar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingFailed() {
pbar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingStarted() {
pbar.setVisibility(View.VISIBLE);
}
});
} else {
holder.imgView.setImageResource(R.drawable.ic_launcher);
}
}
return view;
}
public class ViewHolder {
public TextView tvTitle, tvDesc, tvDate;
private ImageView imgView;
private ProgressBar pbar;
}
}
这个列表视图是通过 json 解析的,所以当我添加一个按钮时,该按钮应该是布局中的第一个按钮所以我的第一个问题是如何将按钮动态添加到主屏幕?第二个问题我应该使用 GridView 来显示按钮或表格布局或其他一些吗?
Plzz 帮助我在 android 编程方面是新手......
提前谢谢。