【发布时间】:2019-07-30 04:30:19
【问题描述】:
我有一个显示 json 的 Activity,它的对象设置为 name 和 link。使用 getName() 向用户显示名称。现在我想实现 onClicklistener 以便新活动将根据位置和等效 url 打开,即 getLink() 相同位置并将其作为附加内容发送到下一个活动。
这是我的列表视图适配器
public class ListViewAdapter extends ArrayAdapter<Hero> {
//the hero list that will be displayed
private List<Hero> heroList;
//the context object
private Context mCtx;
//here we are getting the herolist and context
//so while creating the object of this adapter class we need to give herolist and context
public ListViewAdapter(List<Hero> heroList, Context mCtx) {
super(mCtx, R.layout.vault_list, heroList);
this.heroList = heroList;
this.mCtx = mCtx;
}
//this method will return the list item
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//getting the layoutinflater
LayoutInflater inflater = LayoutInflater.from(mCtx);
//creating a view with our xml layout
View listViewItem = inflater.inflate(R.layout.vault_list, null, true);
//getting text views
Button btn_one = listViewItem.findViewById(R.id.btn_one);
//Getting the hero for the specified position
Hero hero = heroList.get(position);
//setting hero values to textviews
btn_one.setText(hero.getName());
//returning the listitem
return listViewItem;
}
【问题讨论】:
-
照常添加即可。 btn_one.setOnClickListener(new View.OnClickListener(){ .... });
-
你试过onItemClick()
标签: java android android-listview onclick