0

Activity still shows up after calling finish() from one of the listitems view of a listview . I use a viewpager indicator to host a list of fragments . The finish() method is called with an activity object from the list view .

 public View getView(int position , View changeview, ViewGroup container)
 {
    View row_view=changeview;

    if(row_view==null)
    {
     row_view=layoutInflater.inflate(R.layout.rate_cards_list_item,null);   
     viewHolder.rechargeIconListener=new RechargeIconListener()
     viewHolder.topup_recharge_icon.setOnClickListener(viewHolder.rechargeIconListener);
     row_view.setTag(viewHolder);
    }


}

The inner class inside the list adapter

    class RechargeIconListener implements View.OnClickListener
    {
    @Override
    public void onClick(View view) {
            activity_object.setResult(Activity.RESULT_OK,intent);
            activity_object.finish();
            Log.w("activity_object","Activity not finished");
            return;
    }
   }

activity_object is the object of the activity that is passed along with the list adapter's constructor . Also , the activity finishes sometimes , and sometimes not .

user2749265
  • 245
  • 1
  • 4
  • 14

2 Answers2

0

Use a LocalBroadcastManager as described below.

how to use LocalBroadcastManager?

You can register the receiver in the activity and broadcast an intent for the receiver from the list item click. In the onReceive method set the result and finish your activity.

Community
  • 1
  • 1
Ajit Pratap Singh
  • 1,299
  • 12
  • 24
-1

get the context of your activity and call finish()

class RechargeIconListener implements View.OnClickListener
    {
    @Override
    public void onClick(View view) {
            context.finish();
    }
}
Muhammad Aamir Ali
  • 20,419
  • 10
  • 66
  • 57