在 Listview 适配器中实现 onClick 侦听器 class

Implement onClick listener in Listview adapter class

我有一个显示 json 的 Activity 对象设置为 namelink.使用 getName() 向用户显示名称。现在我想实现 onClicklistener,这样新的 activity 将根据位置和等价物 url 打开,即 getLink() 的相同位置并将其作为额外内容发送到下一个 activity。

这是我的列表视图适配器

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;
    }

如果我没理解错的话,你想要使用点击你的列表视图的项目并转到下一个activity和相关的link。你可以实现onItemclick方法来实现你的功能.