0

I have activity A where it has a ADD button when I click on the button it displays the list of users with check boxes in Second Activity and when I select the users and click the conform button it should display in all the users Activity A.I am using adapter to display the users.

from this button I am getting the list of checked values

private void checkButtonClick() 
{
    conform = (Button)findViewById(R.id.Confirm);
    conform.setOnClickListener(new OnClickListener() 
    {
        @Override
        public void onClick(View v) 
        {
            StringBuffer responseText = new StringBuffer();
            responseText.append("The following were selected...\n");

            ArrayList<Namelist> stateList = contactadapteruser.listexample;

            Bundle b=null;
            Namelist state;
            for(int i=0;i<stateList.size();i++)
            {
                state = stateList.get(i);
                b = new Bundle();
                b.putString("selected",state.getName());
                if(state.isSelected())
                {
                    responseText.append("\n" + state.getName());
                }
            }

            Intent i= new Intent(Contactselectuser.this,Contactrepresentativedetails.class);
            i.putExtras(b);
            startActivity(i);
        }         
    }); 
}

from this button I am getting the I am retrieving the values

send.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub

        Intent i2 = getIntent();
        Bundle b1 = i2.getExtras();
        String name1 = b1.getString("selected");
        tweet.setText(name1+",\t");
    }
});

My problem I am unable to get the users which are checked. Can any one help me .

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
Sanjeev
  • 292
  • 2
  • 5
  • 24

2 Answers2

1

use start activity for result to start your second activity.

Intent intent = new Intent(this, SecondActivity.class);
startActivityForResult(intent, 1);

from second activity before closing you can send

Intent return_intent = new Intent();
 return_intent.putExtra("your_user_list",user_list);
 setResult(RESULT_CODE,return_intent);     
 finish();

Now in your FirstActivity override onActivityResult() method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (requestCode == 1) {

     if(resultCode == RESULT_CODE){
         // GET YOUR USER LIST HERE AND USE IT FOR YOUR PURPOSE.    
         user_list=data.getExtra("your_user_list");          
     }
  }
}

You can use broadcast sender and receiver also for your case. But above method is good for your task.

Bharat Sharma
  • 3,926
  • 2
  • 17
  • 29
0
ArrayList<Namelist> stateList = contactadapteruser.listexample;

// convert your ArrayList to a String[]

String[] arr = new String[stateList.size()];

for (int i = 0; i < arr.length; i++)
{
    arr[i] = stateList.get(i).getName();
}

Then using this question as a source, put the String array in your intent:

Bundle b = new Bundle();
b.putStringArray("selected", arr);
Intent i = new Intent(Contactselectuser.this,Contactrepresentativedetails.class);
i.putExtras(b);
startActivity(i);

Then to read the String array from your other activity:

Bundle b = getIntent().getExtras();
String[] array = b.getStringArray("selected");
Community
  • 1
  • 1
Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
  • In for loop how can i check the condition whether it is checked or not – Sanjeev Dec 23 '13 at 10:32
  • hello please reply me how to check the conditon – Sanjeev Dec 23 '13 at 10:36
  • @user3069112 I can't tell you how to check if they check boxes are selected. I don't know anything about your code. You can determine if a checkbox is checked like this though: `checkbox.isChecked()` and it'll return `true` if it is checked, and `false` if it isn't. – Michael Yaworski Dec 23 '13 at 11:23