Question

i'm learning how to change Single item with resultActivity in in my custom Adapter listview. how it's can work ?

this my code when startActivityForResult in custom adapter listview

holder.isi_layout.setOnClickListener(new android.view.View.OnClickListener(){

        public void onClick(View v) 
        {

                            Intent i = null;                                
                            i = new Intent(activity, DetailLaporanActivity.class);                              
                            Bundle b = new Bundle();
                            b.putString("position", Integer.toString(position));

                            i.putExtras(b);
                            activity.startActivityForResult(i, mRequestCode);                                  
                            activity.overridePendingTransition (R.anim.push_left_in, R.anim.push_left_out);


        }
    });                

and this OnResultActivity

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode==mRequestCode) {
            if(resultCode == RESULT_OK){
                String position = data.getStringExtra("position");
                String status_favorite = data.getStringExtra("status_favorite");
                String jumlah_favorite = data.getStringExtra("jumlah_favorite");
                String jumlah_komentar = data.getStringExtra("jumlah_komentar");
            }

            Toast.makeText(getApplicationContext(), "This code Success get Result", Toast.LENGTH_LONG).show();
        }
    }

When i put OnResultActivity in Adapter, code is error, RESULT_OK get notice Cannot be resolved to a variable,

but if i put in MainActivity , this not error but not get value result, i check with Toast.makeText(getApplicationContext(), "This code Success get Result", Toast.LENGTH_LONG).show(); but no toast,....

anybody help me ? how it's work ? sorry, for my english...

Was it helpful?

Solution

You added unresolved RESULT_OK so you should set it in DetailLaporanActivity.class like that.

public class DetailLaporanActivity extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    setResult(RESULT_OK);

  }
}

and than you can use RESULT_OK in your onActivityResult method.

OTHER TIPS

That's because RESULT_OK is a constant of the Activity class. So, you need to qualify it in your Adapter class as so:

Activity.RESULT_OK
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top