androidandroid-intentonclicklistenersimpleadapter

Calling finish() inside onClickListener() of a TextView in SimpleAdapter?


Beginner Android and Java developer here.

I have this snippet of code inside a SimpleAdapter class I use to render a custom list containing a TextView and an ImageView. This is the part for the TextView which processes a URL in another activity.

    for (int i = 0; i < fromList.length; i++) {
        id = mySimpleAdapter.listMap.get(position).get("id");
        holder.textView[i].setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //How to call finish() here for containing Activity?
                Intent i = new Intent (context, Details.class);
                i.putExtra("url", "http://foo.net/do?id="+id);
                context.startActivity(i);
            }
        });
    }

My problem is how to simply call the finish() method of the Activity that contains this SimpleAdapter's linked ListView (to force the Activity to reload completely next time it is called).

Thanks to anyone who answers.


Solution

  • When instantiating the SimpleAdapter, you should pass it an Activity instance instead of Context, and then call finish() on it. Hope this helps.