起价次活动的第一项活动的第二个选项卡片段 [英] Starting Second tab fragment of first activity from second activity
问题描述
我是新来的Android和我停留在这我工作的应用程序的特定部分。问题是 - 我要导航到的第二个选项卡的 HomePageActivity 我在我的 SecondActivity 执行上的 createEvent 按钮onClickListener事件。我试图使用从这里不同的线程和其他网站上的解决方案太多,但我仍然没能得到我的code运行。
I am new to android and I am stuck at particular section of the app which I am working on. The problem is - I want to navigate to the second tab of HomePageActivity when I perform onClickListener event on createEvent button in my SecondActivity. I tried using solution from various threads here and on other sites too but I was still not able to get my code running.
我也有 RecyclerView 在 HomePageActivity 这是一个基于点击事件进行填充。
I also have RecyclerView on HomePageActivity which is to be populated based on the click event.
下面是从两个活动的code片段 -
Here is the code snippet from both the activities -
HomePageActivity.java - 分页活动
public class HomePageActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
fragmentInfo = getIntent().getExtras();
if (fragmentInfo != null)
{
tabNumber = fragmentInfo.getInt("tabNumber");
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
}
public class SectionsPagerAdapter extends android.support.v4.app.FragmentPagerAdapter
{
String[] tabList = {"Communities", "Events", "People"};
public SectionsPagerAdapter(android.support.v4.app.FragmentManager fm)
{
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int position)
{
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount()
{
return tabList.length;
}
@Override
public CharSequence getPageTitle(int position)
{
return tabList[position];
}
}
public static class PlaceholderFragment extends android.support.v4.app.Fragment
{
private static final String ARG_SECTION_NUMBER = "section_number";
public static PlaceholderFragment newInstance(int sectionNumber)
{
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment()
{
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
int viewNumber = getArguments().getInt(ARG_SECTION_NUMBER);
final String[] eventsListArray = {"Event1", "Event2"};
if (viewNumber == 1)
{
View rootView = inflater.inflate(R.layout.fragment_communities, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.communitieslabel);
textView.setText("communities");
return rootView;
}
else if (viewNumber == 2)
{
View rootView = inflater.inflate(R.layout.fragment_events, container, false);
eventsList = (RecyclerView) rootView.findViewById(R.id.recyclerViewEvents);
fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent intent = new Intent(getActivity().getBaseContext(), CreateEvents.class);
startActivity(intent);
}
});
eventsList.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity());
eventsList.setLayoutManager(mLayoutManager);
eventsListAdapter = new RecyclerEventsAdapter(getActivity(), eventListInfo);
eventsList.setAdapter(eventsListAdapter);
return rootView;
}
else
{
View rootView = inflater.inflate(R.layout.fragment_peopleprofile, container, false);
TextView textView = (TextView) rootView.findViewById(R.id.peoplelabel);
textView.setText("people");
return rootView;
}
}
}
}
和从code在 SecondActivity -
And the code from the SecondActivity -
buttonCreateEvent.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String[] eventInfo = new String[0];
getEventName = editTextEventName.getText().toString();
getEventDetail = editTextEventDetails.getText().toString();
getEventLocation = editTextEventLocation.getText().toString();
while (!getEventName.equals("") && !getEventDetail.equals("") && !getEventLocation.equals("") && !getEventDate.equals(""))
{
eventInfo = new String[]{getEventName, getEventDetail, getEventLocation, getEventDate};
}
Intent intent = new Intent(CreateEvents.this, HomePageActivity.class);
intent.putExtra("tabNumber", 2);
intent.putExtra("openEventFragment", eventInfo);
startActivity(intent);
}
});
任何帮助是AP preciated。谢谢你在前进。
Any help is appreciated. Thank you in advance.
推荐答案
您可以致电 getActivity()。getIntent()。getExtras()
获得捆绑
您在其他活动设置的临时演员。
You can call getActivity().getIntent().getExtras()
to get a Bundle
of extras you set in other activity.
这篇关于起价次活动的第一项活动的第二个选项卡片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!