Skip to content Skip to sidebar Skip to footer

I Have Two Activity.i Want To Send The Data From Second Activity To Previous Activity.first Activity Have Custom Listview

I have two activity.I wanna Send the data from second activity to previous activity.First activity have custom List view and bean class.When was i click on second activity,Fist act

Solution 1:

publicvoidaddtocart(){
    addtocart.setOnClickListener(new View.OnClickListener() {
        @Override
        publicvoidonClick(View v) {
            Intent intent=new Intent(QuentityActivity.this,DetaisRESTActivity.class);
            intent.putExtra("MESSAGE",TotAmt);
            startActivity(intent);
            finish();//finishing activity
        }
    });
}

In the first activity then:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState){
     super.onCreate(savedInstanceState);
     Intentc= getIntent();
     Stringmg= c.getStringExtra("MESSAGE");
}

So now you can show the String where you want.

Solution 2:

Do this on second activity class...

publicvoidaddtocart()

{
   addtocart.setOnClickListener(new View.OnClickListener()     
{
            @Override
            publicvoidonClick(View v)     
             {
                  Intent intent=new   Intent(QuentityActivity.this,DetaisRESTActivity.class);
                intent.putExtra("MESSAGE",TotAmt);
                startActivity(intent);
                finish();//finishing activity

            }
        });

}

Now in oncreate() method of first activity class..use this..

if(getIntent().hasExtra("MESSAGE"))
{
   String msg= getIntent().getStringExtra("MESSAGE");

}

Solution 3:

Steps to follow:

  1. You should have to refresh your list view with updated data.
  2. Use adapter.notifyDataSetChanged();

    @OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data)
        {
        super.onActivityResult(requestCode, resultCode, data);
        // check if the request code is same as what is passed  here it is 2if(requestCode==2)
        {
            String message=data.getStringExtra("MESSAGE");
            Log.i("xxxxxxxxxxx",message);
            ruppees.setText(message);
            adapter.notifyDataSetChanged();
    
        }
    }
    

Solution 4:

You have to refresh the list view.first you have to update the listadapterItems. then do it like below code .

//here update your adapter like below,return the position also from the activity in onactivityresult

 ArrayList<ListModel> updatedarraylist = (ArrayList<ListModel>) adapter
                    .getData();
    ListModel sched = updatedarraylist .get(pos);
    sched.setPrice(message);
    updatedarraylist.set(pos,sched);  
    adapter.setData(updatedarraylist );
    adapter.notifyDataSetChanged();

Post a Comment for "I Have Two Activity.i Want To Send The Data From Second Activity To Previous Activity.first Activity Have Custom Listview"