如您所愿,这里有一些代码内容。
public class MyActivity extends TabActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// some other stuff
TabHost.TabSpec firstTab = tabHost.newTabSpec("firstTab");
firstTab.setContent(new Intent(this, FirstTabActivity.class)); // your class with content picker
tabHost.addTab(firstTab);
}
}
这是另一个
public class FirstTabActivity extends Activity
{
private static final int PICK_REQUEST_CODE = 2;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// some stuff
Button pickContactButton = findViewById(R.id.btn_pick_contact);
pickContactButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent intentContact = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intentContact, PICK_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if(PICK_REQUEST_CODE == requestCode && resultCode == RESULT_OK)
{
// do some stuff
}
}
}