我有NewMessage Activity
我正在调用Tab Activity。标签活动包含3个标签Contacts|Group|Selected Contacts
我将在联系人标签上选择一些联系人,并将这些联系人重定向到NewMessage
。没有Tab Activity,这件事情很好。
我引用一些链接
stuck with getting camera pic when using the tab Activity
Android onActivityResult is always 0
我的代码:
调用标签活动
Intent i = new Intent(this,Tab.class);
startActivityForResult(i, REQUEST_PICK_CONTACT);
Tab.Class
public class Tab extends TabActivity {
/** Called when the activity is first created. */
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
android.app.ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
TabHost tabHost = getTabHost();
// Tab for Photos
TabSpec PhoneBook = tabHost.newTabSpec("PhoneBook");
PhoneBook.setIndicator("PhoneBook");
Intent PhoneBook = new Intent(this, Tab1.class);
PhoneBook.setContent(photosIntent);
// Tab for Songs
TabSpec Groups = tabHost.newTabSpec("Groups");
// setting Title and Icon for the Tab
Groups.setIndicator("Groups");
Intent Groups = new Intent(this, Tab2.class);
Groups.setContent(Groups);
// Tab for Videos
TabSpec SelectedContacts = tabHost.newTabSpec("Selected Contacts");
SelectedContacts.setIndicator("Selected Contacts");
Intent SelectedContacts = new Intent(this, Tab3.class);
SelectedContacts.setContent(videosIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(PhoneBook); // Adding PhoneBook
tabHost.addTab(Groups); // Adding Group PhoneBook
tabHost.addTab(SelectedContacts); // Adding SelectedContacts
}
//Menu Bar
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.contact_list, menu);
return super.onCreateOptionsMenu(menu);//This is actionBar Save Button
}
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//Save Button Click
if (id == R.id.action_done)
{
Log.d("Activity","Tab");
}
return super.onOptionsItemSelected(item);
}
}
这是Tab1.Class,我需要传递值ActionBar Save Button Click。
我在Tab.Class中声明了action_bar保存按钮,因为如果我在Tab1.class中声明它没有显示出来。这是我在保存按钮上返回的代码点击
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
//Save Button Click
if (id == R.id.action_done)
{
for(int i = 0; i < ViewContactName.size(); i++)
{
if(ma.mCheckStates.get(i)==true)
{
SelectedName.add(ViewContactName.get(i));
SelectedPhoneNumber.add(ViewContatcPhnoeNo.get(i).replaceAll("[^0-9,+]", ""));
}
}
Intent intent = new Intent();
intent.putStringArrayListExtra("ContactName",(ArrayList<String>) SelectedName);
intent.putStringArrayListExtra("ContactNumber", (ArrayList<String>) SelectedPhoneNumber);
setResult(RESULT_OK, intent);
finish();
}
return super.onOptionsItemSelected(item);
}
那么解决方案是什么?我用了TabHost