1
我有一個ADD按鈕,通過點擊該添加按鈕彈出一個列表視圖,並在該列表視圖的每一行中都有一個按鈕。通過點擊特定行的按鈕(我的意思是該行的文本和圖像)應該作爲圖像按鈕添加到我的應用程序的主屏幕。如何從listView動態添加按鈕?
這是customadapter類的ListView
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幫助IM在機器人編程新....
Thanx提前。
我應該添加到陣列?文字和圖像視圖? sry im在編程方面真的很新穎......如果可以的話,會很感激你的幫助。 – Saad 2013-04-23 05:23:55
現在明白了,謝謝你的幫助 – Saad 2013-04-27 07:10:44