0

I've made a custom contact picker for multiple selection. Now I want to display my selected contact list but I failed to do so. I want to show it at my CreateTab layout. Anyone please help me.

In My CreateTab.class

//To start ContactList.class
private OnClickListener click_listener = new OnClickListener() {

    @Override
    public void onClick(View view) {


        switch(view.getId()) {
        case R.id.add_button:
            Intent i = new Intent(getApplicationContext(), ContactList.class);
            startActivityForResult(i, 100);

            }   
        }       
};


@Override
protected void onActivityResult(int requestCode,int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        data.getExtras().getString("str");
    }
}

In my ContactList.class

             @Override
             public void onClick(View v) {
                 StringBuilder checkedcontacts= new StringBuilder();
                 System.out.println("............"+ma.mCheckStates.size());
                 for(int i = 0; i < name1.size(); i++)
                     {
                     if(ma.mCheckStates.get(i)==true)
                     {
                          checkedcontacts.append(name1.get(i).toString());
                          checkedcontacts.append("\n"); 
                     }

                     else
                     {
                         System.out.println("..Not Checked......"+name1.get(i).toString());
                     }

                 }     

                   Intent i = new Intent();
                   i.putExtra("str", checkedcontacts.toString());
                   setResult(RESULT_OK,i);
                   finish();
             }       
         });
Et Andrea
  • 273
  • 4
  • 21
  • Have you read the answers to this question? http://stackoverflow.com/questions/10407159/android-how-to-manage-start-activity-for-result or this question? http://stackoverflow.com/questions/6548340/onactivityresult-is-never-called?rq=1 – ethan Jul 21 '13 at 12:25

1 Answers1

1

Dont' use RESULT_OK to start the activity for result. Instead use a custom request code.

For example:

int PICK_CONTACT_REQUEST_CODE = 100;
//....
startActivityForResult(i, PICK_CONTACT_REQUEST_CODE ); 
Andy Res
  • 15,963
  • 5
  • 60
  • 96
  • What is the 100? So do I use int PICK_CONTACT_REQUEST_CODE = 100; too in my case? Sorry, I'm newbie – Et Andrea Jul 21 '13 at 12:16
  • Yes, use like that, and of course it does not need to be especially `100`. You can put another number. The idea is that you should start the activity for result with a specific request code. – Andy Res Jul 21 '13 at 12:19
  • I used this code. Please refer, thanks. https://gist.github.com/anonymous/aea19b2be9af9519bbb3. It's not working still . – Et Andrea Jul 21 '13 at 12:24
  • No, no. You still should use `RESULT_OK` in `onActivityResult()`, and to `setResult()`. The only single line that should be modified in your program is this: `startActivityForResult(i, 100); `. And that is all. – Andy Res Jul 21 '13 at 12:26
  • If it still does not make sense, please see this answer on how to use `onActivityResult()`: http://stackoverflow.com/a/10407371/1271435 – Andy Res Jul 21 '13 at 12:30
  • I tried from the example you given, returnIntent.putExtra("result",result); in my case is returnIntent.putExtra("result",checkedcontacts); but putExtra is said to be ambiguous for the type Intent. – Et Andrea Jul 21 '13 at 12:49