1

I am having one Mainactivity in the activity i have given an button if we click the button it shows tabactivity which contains contact and group activity.if we select using checkbox either contact or group it has to automatically comes to the editbox with the content of our selected one.

But right now if i am selecting anything in contact or group its not showing in the edittext.

This is my mainactivity

get.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent i = new Intent(AndroidAlarmSMS.this,
                        AndroidTabLayoutActivity.class);
                startActivityForResult(i, ResultCode);
            }

        });

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

        if (requestCode == ResultCode) {

            if (resultCode == RESULT_OK) {
                sendlist = data.getStringArrayListExtra("name");
                if (sendlist != null) {
                    for (int i = 0; i < sendlist.size(); i++) {
                        edittextSmsNumber.append(sendlist.get(i).toString());
                        edittextSmsNumber.append(";");

                    }
                }


                    }



        }
                //Toast.makeText(AndroidAlarmSMS.this,"wowwww",1000).show();
                if (resultCode == RESULT_CANCELED) {

                }
            }

Here i show my tabactivity also

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabmain);

        TabHost tabHost = getTabHost();

        // Tab for Photos
        TabSpec photospec = tabHost.newTabSpec("Contacts");
        photospec.setIndicator("Contacts", getResources().getDrawable(R.drawable.contact));
       Intent photosIntent = new Intent(this, ContactActivity.class);


        photospec.setContent(photosIntent);


        // Tab for Videos
        TabSpec videospec = tabHost.newTabSpec("Groups");
        videospec.setIndicator("Groups", getResources().getDrawable(R.drawable.group));
        Intent videosIntent = new Intent(this, GroupActivity.class);

        videospec.setContent(videosIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(photospec); // Adding photos tab
         // Adding songs tab 
        tabHost.addTab(videospec); // Adding videos tab

    }

    public  void updateMethod(ArrayList<String> phno0)
    {
        Toast.makeText(this,"hey u came to update method", 1000).show();
        Intent returnIntent = new Intent();
        returnIntent.putStringArrayListExtra("name",phno0);
        setResult(RESULT_OK,returnIntent);     
        super.finish();
    }  
}

These are the child activity which contains tab

contactactivity.java

send.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v) {

                StringBuilder checkedcontacts= new StringBuilder();
                System.out.println(".............."+mAdapter.mCheckStates.size());
                for(int i = 0; i < name1.size(); i++)

                {
                    if(mAdapter.mCheckStates.get(i)==true)
                    {
                        phno0.add(phno1.get(i).toString()) ;
                        checkedcontacts.append(name1.get(i).toString());
                        checkedcontacts.append("\n");

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


                }
                Toast.makeText(ContactActivity.this, checkedcontacts,1000).show();
                AndroidTabLayoutActivity a= new AndroidTabLayoutActivity();
                a.updateMethod(phno0);

            }       
        });

like this in group activity also.

while selecting the checkbox of contact or group its not coming to editbox thats the problem

Karthick M
  • 769
  • 2
  • 11
  • 29

1 Answers1

0

How to return a result (startActivityForResult) from a TabHost Activity?

After checking this link i am giving solution for your question.

Toast.makeText(ContactActivity.this, checkedcontacts,1000).show();
    Intent returnIntent = new Intent();
    returnIntent.putStringArrayListExtra("name",phno0);
    if (getParent() == null) {
        setResult(Activity.RESULT_OK, returnIntent);
    } else {
        getParent().setResult(Activity.RESULT_OK, returnIntent);
    }
    finish();

for more information you check the above link

Community
  • 1
  • 1
vineeth
  • 61
  • 3