I know a lot of questions just like this one have been asked, but I didn't see any real similarity to this case.
I'm using the android android.support.v4.app.DialogFragment and android.support.v4.app.Fragment
I'm trying show web service response in a Popup View containing swipe views, so I'm using a DialogFragment and inside it is a ViewPager, and of course there is a ListView inside each fragment in the ViewPager to show the results.
Code:Activity that shows the Dialog
new ResultFragmentDialog().show(getSupportFragmentManager(), TAG_RESULT_DIALOG_FRAGMENT);
ResultFragmentDialog code:
public class ResultFragmentDialog extends DialogFragment {
private View view;
private ViewPager pager;
private FragmentsResultAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.dialog_result, container, false);
Dialog dialog = getDialog();
dialog.setOnShowListener(new OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
//Im creating the adapter here because if I don't there will be an IllegalArgumentException: No view found for id for fragment ..
pager = (ViewPager) view.findViewById(R.id.pager);
adapter = new FragmentsResultAdapter(getChildFragmentManager());
pager.setAdapter(adapter);
}
});
return view;
}
private class FragmentsResultAdapter extends FragmentStatePagerAdapter {
private ResultListDialogFragment firstFragment;
private ResultListDialogFragment secondFragment;
public FragmentsResultAdapter(FragmentManager fm) {
super(fm);
firstFragment = new ResultListDialogFragment();
secondFragment = new ResultListDialogFragment();
}
#Override
public int getCount() {
return 2;
}
#Override
public boolean isViewFromObject(View arg0, Object arg1) {
return false;
}
#Override
public CharSequence getPageTitle(int position) {
return position == 0 ? "First" : "Second";
}
#Override
public Fragment getItem(int position) {
return position == 0 ? firstFragment : secondFragment;
}
#Override
public int getItemPosition(Object object){
return PagerAdapter.POSITION_NONE;
}
}
}
ResultListDialogFragment code:
public class ResultListDialogFragment extends Fragment {
private View view;
private ListView list;
private ResultAdapter adapter;
private ResponseMultipleItems result = new ResponseMultipleItems();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_dialog_result_lst, container, false);
list = (ListView) view.findViewById(R.id.lstResult);
list.setOnItemClickListener(adapter);
adapter = new ResultAdapter(getActivity());
list.setAdapter(adapter);
return view;
}
public void loadResult(List<Item> result) {
result.setResult(result);
adapter.notifyDataSetChanged();
}
public void clear() {
result.getResult().clear();
notifyDataSetChanged();
}
private class ResultAdapter extends BaseAdapter implements OnItemClickListener {
private Context context;
private ResultItem item;
private Holder holder;
public ResultAdapter(Context context) {
this.context = context;
}
#Override
public int getCount() {
return result.getResult().size();
}
#Override
public Object getItem(int position) {
return result.getResult().get(position);
}
#Override
public long getItemId(int position) {
return result.getResult().get(position).getId();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
item = result.getResult().get(position);
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.item_result, parent, false);
holder = new Holder();
holder.txt = (TextView) convertView.findViewById(R.id.txtTitle);
convertView.setTag(holder);
}
holder = (Holder) convertView.getTag();
if (position == result.getResult().size() - 1 && result.isHasMore()) {
holder.txt.setText("Load more");
} else {
holder.txt.setText(item.getTitle());
}
return convertView;
}
private class Holder {
TextView txt;
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
}
ViewPager code in layout file:
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
ListView code in layout file:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lstResult"
android:layout_width="match_parent"
android:layout_height="match_parent" />
And finally the problem is that the created ListView inside the fragment has a height of 0 !!!
How did I know that the lists in both fragments have the height of zero? I didn't know at the beginning, but the public View getView(int position, View convertView, ViewGroup parent) inside the ResultAdapter is not getting called, while the public int getCount() all ways gets called after the notifyDataSetChanged() is called.
So I used the HeirarchyViewer and it shows DialogFragment has a normal height, the NoSaveStateFrameLayout for each fragment getHeight() attr from the heirarchyviewer shows 0, and the ListView inside the NoSaveStateFrameLayout also have a 0 height.
The Dialog is displayed successfully and I can swipe between two invisible views !!
The background code I didn't write successfully fetches the content and passes them to the adapter, yet the public View getView(int position, View convertView, ViewGroup parent) is not triggered !!
tried to use wrap_content instead of match_parent didn't work.
tried getLayoutParams().height = 100 after creating the listviews also didn't work.
tried setting a new LayoutParam with new width and height, also didn't work.
tried to use a Dialog instead of DialogFragment also didn't work.
Related
Good morning,
I have a Fragment which its layout has a ViewPager, I provide a custom PageAdapter to show two child layouts. One layout is to fill with personal data and another layout is to fill with Address data by the user. On my fragment I want to retrieve both layouts data and fill a object Pessoa(Person) with an attribute Endereco (Address). So far my ViewPager is working and both layout are displayed, however when I try to get the fields on both layouts, either on onCreateView or onResume fragment's method, using :
viewpager.getChildAt(0).findViewById(R.id.txt1)
I got an NullPointerException, but if I add an OnPageChangeListener this works, I not sure if it's the best approach. Is There a best place to retrieve a reference to the viewpager child's layout?
Ps. I don't want to use two other Fragments in order to display each of the layouts.
PageAdapter
public class ViewPagerCadastroPessoaAdapter extends PagerAdapter {
private Context context;
private int[] views = {R.layout.layout_cadastro_dados_pessoais,R.layout.layout_cadastro_endereco };
public ViewPagerCadastroPessoaAdapter(Context context) {
this.context = context;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(this.context);
View layout = inflater.inflate(views[position], container, false);
container.addView(layout, position);
return layout;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "Dados Pessoais";
case 1:
return "Endereço";
}
return super.getPageTitle(position);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}}
ViewPager's holder Fragment
public class CadastroPessoaFragment extends Fragment {
private ViewPager viewPagerCadastroPessoa;
private TabLayout tabLayoutCadastroPessoa;
public CadastroPessoaFragment() {
}
public static CadastroPessoaFragment newInstance() {
return new CadastroPessoaFragment();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_cadastro_pessoa, container, false);
tabLayoutCadastroPessoa = root.findViewById(R.id.tabLayoutCadastroPessoa);
viewPagerCadastroPessoa = root.findViewById(R.id.viewPagerCadastroPessoa);
viewPagerCadastroPessoa.setOffscreenPageLimit(2);
viewPagerCadastroPessoa.setAdapter(new ViewPagerCadastroPessoaAdapter(getContext()));
tabLayoutCadastroPessoa.setupWithViewPager(viewPagerCadastroPessoa);
int cor = ContextCompat.getColor(getContext(), android.R.color.white);
tabLayoutCadastroPessoa.setTabTextColors(cor, cor);
//get a null pointer
viewPagerCadastroPessoa.getChildAt(0).findViewById(R.id.txt1);
viewPagerCadastroPessoa.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
//works fine
viewPagerCadastroPessoa.getChildAt(0).findViewById(R.id.txt1);
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
return root;
}
#Override
public void onResume() {
super.onResume();
//get a null pointer
viewPagerCadastroPessoa.getChildAt(0).findViewById(R.id.txt1);
}
}
Thank you all in advance
UPDATE
According with
Anton Malyshev answer
The way Viewpager creates its pages is kind of "unsynchronized", so I used the following approach to solve my problem:
On my custom adapter I definied an interface with a single method onViewPagerReady(), as my Viewpager will always have only two pages, inside instantiateItem I check when position is 1 (once position starts with 0), if position == 1 I call the method onViewPagerReady that my fragment viewpager's holder implements, so inside this method I retrieve the layout of viewpager's children
public class ViewPagerCadastroPessoaAdapter extends PagerAdapter {
public interface ViewPagerObserver{
void onViewPagerReady();
}
private Context context;
private int[] views = {R.layout.layout_cadastro_dados_pessoais,R.layout.layout_cadastro_endereco };
private ViewPagerObserver observer;
public ViewPagerCadastroPessoaAdapter(Context context, ViewPagerObserver observer) {
this.context = context;
this.observer = observer;
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater = LayoutInflater.from(this.context);
View layout = inflater.inflate(views[position], container, false);
container.addView(layout, position);
if(position == 1){
observer.onViewPagerReady();
}
return layout;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public int getCount() {
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "Dados Pessoais";
case 1:
return "Endereço";
}
return super.getPageTitle(position);
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
Fragment Viewpager's Holder
#Override
public void onViewPagerReady() {
View rootCadastroDadosPessoais = viewPagerCadastroPessoa.getChildAt(0);
View rootCadastroEnderecos =viewPagerCadastroPessoa.getChildAt(1);
}
Thank you all.
Just wait until viewPagerCadastroPessoa.getChildCount() will be greater than 0. The pages in ViewPager are not created yet in onResume (they are created asynchronously).
I have a viewpager in a fragment. My viewpager has 3 tabs, Each tab has a listview. i want to set item click listener for each item of listview to go to another fragment, But I can't setOnItemClickListener for second tab & third tab, Just first tab works. Every SetOnClickListener is correct. Help Me Please!
ViewPager XML
<android.support.v4.view.ViewPager
android:id="#+id/vpPager"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_header"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_gravity="top"
android:paddingBottom="4dp"
android:textColor="#color/RakaarColor"
android:paddingTop="4dp" />
</android.support.v4.view.ViewPager>
ViewPager Class
public class ProjectsFragment extends Fragment {
MyPagerAdapter adapterViewPager;
public static class MyPagerAdapter extends FragmentPagerAdapter {
private static int NUM_ITEMS = 3;
String[] titles = {"MyWorks", "SentBids", "ExistProject"};
public MyPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}
// Returns total number of pages
#Override
public int getCount() {
return NUM_ITEMS;
}
// Returns the fragment to display for that page
#Override
public Fragment getItem(int position) {
switch (position) {
case 0: // Fragment # 0 - This will show FirstFragment
return MyWorksFragment.newInstance(0);
case 1: // Fragment # 0 - This will show FirstFragment different title
return SentBidsFragment.newInstance(1);
case 2: // Fragment # 1 - This will show SecondFragment
return ExistProjectsFragment.newInstance(2);
default:
return null;
}
}
// Returns the page title for the top indicator
#Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
}
public ProjectsFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_projects, container, false);
ViewPager vpPager = (ViewPager) view.findViewById(R.id.vpPager);
adapterViewPager = new MyPagerAdapter(getChildFragmentManager());
vpPager.setAdapter(adapterViewPager);
vpPager.setOffscreenPageLimit(0);
vpPager.setCurrentItem(3);
PagerTabStrip pagerTabStrip = (PagerTabStrip) view.findViewById(R.id.pager_header);
pagerTabStrip.setDrawFullUnderline(true);
pagerTabStrip.setTabIndicatorColor(Color.parseColor("#44b1c5"));
Typeface IRANSansFaNum = Typeface.createFromAsset(getActivity().getAssets(), "fonts/IRANSansMobile.TTF");
for (int i = 0; i < pagerTabStrip.getChildCount(); ++i) {
View nextChild = pagerTabStrip.getChildAt(i);
if (nextChild instanceof TextView) {
TextView textViewToConvert = (TextView) nextChild;
textViewToConvert.setTypeface(IRANSansFaNum);
}
}
Button plus = (Button)view.findViewById(R.id.projects_plus_button);
plus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
AddFragment Add = new AddFragment();
FragmentManager manager = getActivity().getSupportFragmentManager();
manager.beginTransaction().replace(R.id.mycontainer, Add).addToBackStack("Back").commit();
}
});
return view;
}
One Example Of My Adapters
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_exist_projects, container, false);
ProjectsAdapter madapter;
plistnewsData.clear();
ListView exist_projects_listview = (ListView)view.findViewById(R.id.exist_projects_listview);
plistnewsData.add(new ProjectsAdapterItems("Name", "Details", "Cost", "Day", "Date", "120 Bids"));
madapter = new ProjectsAdapter(plistnewsData);
exist_projects_listview.setAdapter(madapter);
exist_projects_listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ProjectsItemsFragment Add = new ProjectsItemsFragment();
FragmentManager manager = getActivity().getSupportFragmentManager();
manager.beginTransaction().replace(R.id.mycontainer, Add).addToBackStack("Back").commit();
SharedPreferences pos = getActivity().getSharedPreferences("position", Context.MODE_PRIVATE);
SharedPreferences.Editor posEdit = pos.edit();
posEdit.putString("position", "" + position);
posEdit.commit();
}
});
return view;
}
private class ProjectsAdapter extends BaseAdapter {
public ArrayList<ProjectsAdapterItems> plistnewsDataAdpater ;
public ProjectsAdapter(ArrayList<ProjectsAdapterItems> plistnewsDataAdpater) {
this.plistnewsDataAdpater=plistnewsDataAdpater;
}
#Override
public int getCount() {
return plistnewsDataAdpater.size();
}
#Override
public String getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater mInflater = getActivity().getLayoutInflater();
View myView = mInflater.inflate(R.layout.title_of_firstlistview, null);
final ProjectsAdapterItems p = plistnewsDataAdpater.get(position);
TextView name = (TextView)myView.findViewById(R.id.projects_name);
name.setText(p.pname);
TextView details = (TextView)myView.findViewById(R.id.projects_details);
details.setText(p.pdetails);
TextView cost = (TextView)myView.findViewById(R.id.projects_cost);
cost.setText(p.pcost);
TextView day = (TextView)myView.findViewById(R.id.projects_day);
day.setText(p.day);
TextView date = (TextView)myView.findViewById(R.id.projects_date);
date.setText(p.date);
TextView bids = (TextView)myView.findViewById(R.id.project_propsal);
bids.setText(p.bids);
return myView;
}
}
}
I've checked this question on SO where I basically have the same issue.
The difference is that I am not using an Adapter Class in my project, I only have a TabActivity.java (android studio default) that populated my fragments.
I have already followed all the steps in the questions answer however I do not understand the third step.
3.Code of Adapter(Adapter_Contacts.java in my case)
Where should I put this code because in my case I do not use any Adapter Class
this is my fragment adapter inside tabactivity.java
public class SectionsPagerAdapter extends FragmentPagerAdapter{
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch (position){
case 0:
return new BrowseTitle();
case 1:
return new ChatHistory();
default:
break;
}
return null;
}
#Override
public int getCount() {
// Show 2 total pages.
return 2;
}
#Override
public CharSequence getPageTitle(int position) {
return null;
}
}
and this is one of my fragment that populated inside tabactivity
public class BrowseTitle extends Fragment {
private DatabaseReference mRootRef;
private ListView listView;
private ArrayAdapter<String> arrayAdapter;
private ArrayList<String> list_of_thread = new ArrayList<>();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
//Overriden method onCreateView
#Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_browse_title, container, false);
//this is the logic
mRootRef = FirebaseDatabase.getInstance().getReference().child("tdesc");
listView = (ListView) v.findViewById(R.id.titleList);
arrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),android.R.layout.simple_list_item_1,list_of_thread){
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view =super.getView(position, convertView, parent);
TextView textView=(TextView) view.findViewById(android.R.id.text1);
//changin text color
textView.setTextColor(Color.BLACK);
return view;
}
};
listView.setAdapter(arrayAdapter);
public void beginSearch(String query) {
Log.e("QueryFragment", query);
arrayAdapter.getFilter().filter(query);
}
}
Is there a way I can implement this correctly?
i'm trying to put ViewPager into ListView
here the code of ListView AdapterClass:
public class AdapterPager extends BaseAdapter {
.....
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
view = lInflater.inflate(R.layout.component_pager, parent, false);
new ViewHolder(view, itemData.get(position));
}
return view;
}
View Holder:
private class ViewHolder {
ViewPager pager;
PagerAdapter pagerAdapter;
public ViewHolder(View view, ModelItem model){
pager = (ViewPager) view.findViewById(R.id.pager);
pager.setId(model.getId()); /// uniq ID
pagerAdapter = new MyFragmentPagerAdapter(((FragmentActivity)view.getContext()).getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
}
then, Pager Adapter:
static final int PAGE_COUNT = 2;
private class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
return FragmentComponentPager.newInstance(position, mModel);
}
#Override
public float getPageWidth(int position) {
float f_width = 1f;
return f_width;
}
#Override
public int getCount() {
return PAGE_COUNT;
}
}
and, the last, Pager Fragment:
public class FragmentComponentPager extends Fragment {
static final String ARGUMENT_PAGE_NUMBER = "arg_page_number";
static final String ARGUMENT_NAME = "arg_name";
int pageNumber;
public static FragmentComponentPager newInstance(int page, ModelItem data) {
FragmentComponentPager pageFragment = new FragmentComponentPager();
Bundle arguments = new Bundle();
arguments.putInt(ARGUMENT_PAGE_NUMBER, page);
if (data != null){
arguments.putString(ARGUMENT_NAME, data.getName());
}
pageFragment.setArguments(arguments);
return pageFragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pageNumber = getArguments().getInt(ARGUMENT_PAGE_NUMBER);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.component_list, null);
TextView tvTitle = (TextView) view.findViewById(R.id.tvTitle);
tvTitle.setText(getArguments().getString(ARGUMENT_NAME));
return view;
}
}
when i run it ListView shows all items that i've added, but all of them, except the last one, with empty ViewPager.
and, if i removed pager.setId(model.getId()); the first item shows view pager, and the others empty.
guess that smth wrong with FragmentManager, but have no idea how deal with it :(
In your ViewHolder you need to call getChildFragmentManager instead of getSupportFragmentManager.
I got stuck into the problem with listview used with fragment inside viewpager styled tabs that given in jakewharton's Android-ViewPagerIndicator... example on github.
i am using the same lib for three tabs each having a list view with same arraylist set to there adapters.
I am using 3 this kind of fragment all are working fine but as i want my list to be updated in all other fragments when i make changes in any one of them, it is not reflecting the changes.
i want if i checked a checkbox in any one of the list among three tabs (i am updating values in db and my arraylist) other two listview inside their respective fragments should reflect changes, please help me on this.
please help me on this, any help would be appreciated
class RingFragment extends Fragment
{
public static RingFragment newInstance(Context c, ArrayList<Ringtones> ringList)
{
RingFragment fragment = new RingFragment();
cCntxt = c;
return fragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState)
{
rngAdapter = new RingAdapter(cCntxt, ringFragList);
lstRingtones = new ListView(cCntxt);
lstRingtones.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
lstRingtones.setAdapter(rngAdapter);
LinearLayout layout = new LinearLayout(getActivity());
layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
layout.setGravity(Gravity.CENTER);
layout.addView(lstRingtones);
return layout;
}
public class RingAdapter extends BaseAdapter
{
ArrayList<Ringtones> arlstRingAdpter;
Context adptrContext;
public boolean noRing = false;
public RingAdapter(Context c, ArrayList<Ringtones> adptrRngtones)
{
arlstRingAdpter = adptrRngtones;
adptrContext = c;
}
#Override
public int getCount()
{
return arlstRingAdpter.size();
}
#Override
public Object getItem(int position)
{
return position;
}
#Override
public long getItemId(int position)
{
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
final Wrapper wrapper;
if (view == null)
{
view = (RelativeLayout)LayoutInflater.from(cCntxt).inflate(R.layout.cell_ringtone,
null);
wrapper = new Wrapper(view);
view.setTag(wrapper);
}
else
{
wrapper = (Wrapper) view.getTag();
}
return view;
}
}
}
}
:->My Main Activity from where i am calling these fragments is
public class MainActivity extends FragmentActivity
{
ViewPager mPager;
PageIndicator mIndicator;
MusicAdapter mAdapter;
RingtonesBL rngBL;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAdapter = new MusicAdapter(getSupportFragmentManager());
mPager = (ViewPager)findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(mPager);
}
class MusicAdapter extends RingtoneFragmentAdapter
{
public MusicAdapter(FragmentManager fm)
{
super(fm);
}
#Override
public Fragment getItem(int position)
{
if(position % CONTENT.length == 0)
{
return
RingFragment.newInstance(AppConstants.cAppContext,AppConstants.arlst_RingAll);
}
else if(position % CONTENT.length == 1)
{
return RingFragment1.newInstance(AppConstants.cAppContext,
AppConstants.arlst_RingCart);
}
else
{
return RingFragment2.newInstance(AppConstants.cAppContext,
AppConstants.arlst_RingPurchased);
}
}
public int getItemPosition(Object object)
{
return POSITION_NONE;
}
#Override
public int getCount()
{
return CONTENT.length;
}
#Override
public CharSequence getPageTitle(int position)
{
return CONTENT[position % CONTENT.length].toUpperCase();
}
}
}
activity_main.xml having only
<com.ringtone.TabPageIndicator
android:id="#+id/indicator"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/indicator"
>
</android.support.v4.view.ViewPager>
Please tell me how can i notify the other fragments listview while changing in any one.
Please try to do stuff out of this branches:
for example:
else
{
wrapper = (Wrapper) view.getTag();
}
wrapper.txtText.setText("Refreshed");
return view;
}