Search Results

Search found 29 results on 2 pages for 'viewpager'.

Page 1/2 | 1 2  | Next Page >

  • Android ViewPager Displaying TextView in Layout

    - by Ammonious
    I'm having a problem getting my viewpager to work correctly. Currently the bottom part of my layout will page across but the remaining part will not Here's my code that I have in my PageAdapter public class MyPageAdapter extends PagerAdapter { public int getCount() { return 31; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resId = 0; switch (position) { case 0: resId = R.layout.main_menu; break; case 1: resId = R.layout.article1; break; case 2: resId = R.layout.article2; break; .... .... View view = inflater.inflate(resId, null); ((ViewPager) collection).addView(view, 0); return view; This is what I have for my XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/background" android:clickable="true" android:id="@+id/layout13" android:weightSum="0"> <TextView android:id="@+id/textView01" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:padding="12dp" android:text="@string/article13" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000" /> <TextView android:id="@+id/textView02" android:layout_width="match_parent" android:layout_height="302dp" android:gravity="center_vertical|center_horizontal" android:text="@string/body13" android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#000000" /> <android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@id/viewPager" > </android.support.v4.view.ViewPager> </LinearLayout> I've tried Moving the around in my XML layout to right underneath my LinearLayout and i get the full screen but all my text disappears. It's probably something simple i'm missing but any help on this would be greatly appreciated!

    Read the article

  • Different positions in ViewPager

    - by Kalai Selvan.G
    In my Application am using ViewPager to swipe the images,which comes through webservice as URL. Everything goes smoothly,the problem is while swiping myself getting the position as collapsed one.. Swipe left-right: positions are 1,2,3,4,5,etc.. if i stops swiping at 5th pos and started to Swipe from right-left: positions are 2,1...why this happens? I need to catch the position of the imageURL to find out the ID of the specific image and so i need to download and set it as wallpaper.. Normally while we swipe from right-left,the positions should decrease like 4,3,2,1. Also in debugger mode i got some start position,end position,last position with different values.. Any Clue about ViewPager. Here is my code: public class ImagePagerActivity extends BaseActivity { private ViewPager pager; private DisplayImageOptions options; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ac_image_pager); Bundle bundle = getIntent().getExtras(); String[] imageUrls = bundle.getStringArray(Extra.IMAGES); int pagerPosition = bundle.getInt(Extra.IMAGE_POSITION, 0); options = new DisplayImageOptions.Builder() .showImageForEmptyUrl(R.drawable.image_for_empty_url) .cacheOnDisc() .decodingType(DecodingType.MEMORY_SAVING) .build(); pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new ImagePagerAdapter(imageUrls)); pager.setCurrentItem(pagerPosition); } private class ImagePagerAdapter extends PagerAdapter { private String[] images; private LayoutInflater inflater; ImagePagerAdapter(String[] images) { this.images = images; inflater = getLayoutInflater(); } @Override public void destroyItem(View container, int position, Object object) { ((ViewPager) container).removeView((View) object); } @Override public void finishUpdate(View container) { } @Override public int getCount() { return images.length; } @Override public Object instantiateItem(View view, int position) { final FrameLayout imageLayout = (FrameLayout) inflater.inflate(R.layout.item_pager_image, null); final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image); final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading); imageLoader.displayImage(images[position], imageView, options, new ImageLoadingListener() { public void onLoadingStarted() { spinner.setVisibility(View.VISIBLE); } public void onLoadingFailed() { spinner.setVisibility(View.GONE); imageView.setImageResource(android.R.drawable.ic_delete); } public void onLoadingComplete() { spinner.setVisibility(View.GONE); } }); ((ViewPager) view).addView(imageLayout, 0); return imageLayout; } @Override public boolean isViewFromObject(View view, Object object) { return view.equals(object); } @Override public void restoreState(Parcelable state, ClassLoader loader) { } @Override public Parcelable saveState() { return null; } @Override public void startUpdate(View container) { } } }

    Read the article

  • How to refresh a fragment in a viewpager?

    - by aut_silvia
    I know there are already some questions to this problem. But I am really new in Android and ecspecially to Fragments and Viewpager. Pls have passion with me. I didn't found a answer which fits to my code. I dont know how to refresh a fragment or reload it when it's "active" again. TabsPagerAdapter.java: public class TabsPagerAdapter extends FragmentPagerAdapter{ public TabsPagerAdapter(FragmentManager fm){ super(fm); } @Override public Fragment getItem(int index) { switch (index) { case 0: return new KFZFragment(); case 1: return new LogFragment(); case 2: return new TrackFragment(); } return null; } @Override public int getCount() { // get item count - equal to number of tabs return 3; } } I have this 3 Fragments (KFZFragment,LogFragment,TrackFragment) and on the TrackFragment I calculate some data and this data should be display in a ListView in LogFragment. But when I change to LogFragment it's not the latest data. So it doesnt refresh. Now how should I modify my code to refresh the fragments when it's "active"? MainActivityFragment.java: public class MainActivityFragment extends FragmentActivity implements ActionBar.TabListener{ private ViewPager viewPager; private TabsPagerAdapter mAdapter; private ActionBar actionBar; List<Fragment> fragments; private String[] tabs = { "KFZ", "Fahrten Log", "Kosten Track" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_fragment); // Initilization viewPager = (ViewPager) findViewById(R.id.pager); actionBar = getActionBar(); mAdapter = new TabsPagerAdapter(getSupportFragmentManager()); fragments = new Vector<Fragment>(); fragments.add(Fragment.instantiate(this, KFZFragment.class.getName(),savedInstanceState)); fragments.add(Fragment.instantiate(this, LogFragment.class.getName(),savedInstanceState)); viewPager.setAdapter(mAdapter); actionBar.setHomeButtonEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Adding Tabs for (String tab_name : tabs) { actionBar.addTab(actionBar.newTab().setText(tab_name) .setTabListener(this)); } viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // on changing the page // make respected tab selected actionBar.setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } @Override public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { } return super.onKeyDown(keyCode, event); } } Pls help me out.

    Read the article

  • Duplication of menu items with ViewPager and Fragments

    - by Julian
    I'm building an Android Application (minimum SDK Level 10, Gingerbread 2.3.3) with some Fragments in a ViewPager. I'm using ActionBarSherlock to create an ActionBar and android-viewpagertabs to add tabs to the ViewPager just like in the Market client. I have one global menu item that I want to be shown on every tab/fragment. On the first of the three tabs I want to have two additional menu items. But now two strange things happen: First if I start the app, everything seems to be fine, I can see all three menu items on the first page and only one item if i swipe to the second and third tab. But if I swipe back to the second tab from the third one, I can see all three items again which shouldn't happen. If I swipe back to the first and then again to the second tab, everything is fine again. The other strange thing is that every time I rotate the device, the menu items from the fragment are added again, even though they are already in the menu. Code of the FragmentActivity that displays the ViewPager and its tabs: public class MainActivity extends FragmentActivity { public static final String TAG = "MainActivity"; private ActionBar actionBar; private Adapter adapter; private ViewPager viewPager; private ViewPagerTabs tabs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.volksempfaenger); actionBar = getSupportActionBar(); adapter = new Adapter(getSupportFragmentManager()); adapter.addFragment(getString(R.string.title_tab_subscriptions), SubscriptionGridFragment.class); // adding more fragments here viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setAdapter(adapter); tabs = (ViewPagerTabs) findViewById(R.id.tabs); tabs.setViewPager(viewPager); } public static class Adapter extends FragmentPagerAdapter implements ViewPagerTabProvider { private FragmentManager fragmentManager; private ArrayList<Class<? extends Fragment>> fragments; private ArrayList<String> titles; public Adapter(FragmentManager fm) { super(fm); fragmentManager = fm; fragments = new ArrayList<Class<? extends Fragment>>(); titles = new ArrayList<String>(); } public void addFragment(String title, Class<? extends Fragment> fragment) { titles.add(title); fragments.add(fragment); } @Override public int getCount() { return fragments.size(); } public String getTitle(int position) { return titles.get(position); } @Override public Fragment getItem(int position) { try { return fragments.get(position).newInstance(); } catch (InstantiationException e) { Log.wtf(TAG, e); } catch (IllegalAccessException e) { Log.wtf(TAG, e); } return null; } @Override public Object instantiateItem(View container, int position) { FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); Fragment f = getItem(position); fragmentTransaction.add(container.getId(), f); fragmentTransaction.commit(); return f; } } @Override public boolean onCreateOptionsMenu(Menu menu) { BaseActivity.addGlobalMenu(this, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { return BaseActivity.handleGlobalMenu(this, item); } } Code of the fragment that shall have its own menu items: public class SubscriptionGridFragment extends Fragment { private GridView subscriptionList; private SubscriptionListAdapter adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } // ... @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.subscription_list, menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // ... } }

    Read the article

  • ViewPager cycle between views?

    - by Erdem Azakli
    I want my ViewPager implementation to cycle between views instead of stopping at the last view. For example, if I have 3 views to display via a ViewPager, it should return back to the first View after the third View on fling instead of stopping at that third view. I want it to return to the first page/view when the user flings forward on the last page Thanks, Mypageradapter; package com.example.pictures; import android.content.Context; import android.media.AudioManager; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; public class MyPagerAdapter extends PagerAdapter{ SoundManager snd; int sound1,sound2,sound3; boolean loaded = false; public int getCount() { return 6; } public Object instantiateItem(View collection, int position) { View view=null; LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.setVolumeControlStream(AudioManager.STREAM_MUSIC); int resId = 0; switch (position) { case 0: resId = R.layout.picture1; view = inflater.inflate(resId, null); break; case 1: resId = R.layout.picture2; view = inflater.inflate(resId, null); break; case 2: resId = R.layout.picture3; view = inflater.inflate(resId, null); break; case 3: resId = R.layout.picture4; view = inflater.inflate(resId, null); break; case 4: resId = R.layout.picture5; view = inflater.inflate(resId, null); break; case 5: resId = R.layout.picture6; view = inflater.inflate(resId, null); break; } ((ViewPager) collection).addView(view, 0); return view; } @SuppressWarnings("unused") private Context getApplicationContext() { // TODO Auto-generated method stub return null; } private void setVolumeControlStream(int streamMusic) { // TODO Auto-generated method stub } @SuppressWarnings("unused") private Context getBaseContext() { // TODO Auto-generated method stub return null; } @SuppressWarnings("unused") private PagerAdapter findViewById(int myfivepanelpager) { // TODO Auto-generated method stub return null; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } public static Integer getItem(int position) { // TODO Auto-generated method stub return null; } } OnPageChangeListener; package com.example.pictures; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Pictures extends Activity implements OnPageChangeListener{ SoundManager snd; int sound1,sound2,sound3; View view=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picturespage); MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); myPager.setOnPageChangeListener(this); snd = new SoundManager(this); sound1 = snd.load(R.raw.sound1); sound2 = snd.load(R.raw.sound2); sound3 = snd.load(R.raw.sound3); } public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } public void onPageSelected(int position) { // TODO Auto-generated method stub switch (position) { case 0: snd.play(sound1); break; case 1: snd.play(sound2); break; case 2: snd.play(sound3); break; case 3: Toast.makeText(this, "1", Toast.LENGTH_SHORT).show(); break; case 4: Toast.makeText(this, "2", Toast.LENGTH_SHORT).show(); break; case 5: Toast.makeText(this, "3", Toast.LENGTH_SHORT).show(); break; } } };

    Read the article

  • How to add a Fragment inside a ViewPager using Nested Fragment (Android 4.2)

    - by sabadow
    I have a ViewPager with three Fragments, each one shows a List (or Grid). In the new Android API level 17 (Jelly Bean 4.2), one of the features is Nested Fragments. The new functionality description says: if you use ViewPager to create fragments that swipe left and right and consume a majority of the screen space, you can now insert fragments into each fragment page. So, if I understand right, now I can create a ViewPager with Fragments (with a button inside for example) inside, and when user press the button show another Fragment without loose the ViewPager using this new feature. I expend my morning trying to implement this on several ways but I can´t made it... Can somebody show a simple example of how to do this? PS: I'm only interested in doing at this way, with getChildFragmentManager to learn how works.

    Read the article

  • How to add OnClickListener in ViewPager

    - by Erdem Azakli
    I have problem with ViewPager and can't find answer.I want to Toast a message when pictures(view) clicked. I can't make, please help me. Example: click on the picture1 --Message"Picture1" click on the picture2 --Message"Picture2" Thanks a lot, Mypageradapter; package com.example.pictures; import android.content.Context; import android.media.AudioManager; import android.os.Parcelable; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; public class MyPagerAdapter extends PagerAdapter{ public int getCount() { return 6; } public Object instantiateItem(View collection, int position) { View view=null; LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resId = 0; switch (position) { case 0: resId = R.layout.picture1; view = inflater.inflate(resId, null); break; case 1: resId = R.layout.picture2; view = inflater.inflate(resId, null); break; case 2: resId = R.layout.picture3; view = inflater.inflate(resId, null); break; case 3: resId = R.layout.picture4; view = inflater.inflate(resId, null); break; case 4: resId = R.layout.picture5; view = inflater.inflate(resId, null); break; case 5: resId = R.layout.picture6; view = inflater.inflate(resId, null); break; } ((ViewPager) collection).addView(view, 0); return view; } @SuppressWarnings("unused") private Context getApplicationContext() { // TODO Auto-generated method stub return null; } private void setVolumeControlStream(int streamMusic) { // TODO Auto-generated method stub } @SuppressWarnings("unused") private Context getBaseContext() { // TODO Auto-generated method stub return null; } @SuppressWarnings("unused") private PagerAdapter findViewById(int myfivepanelpager) { // TODO Auto-generated method stub return null; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } public static Integer getItem(int position) { // TODO Auto-generated method stub return null; } } OnPageChangeListener; package com.example.pictures; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.widget.Button; import android.widget.Toast; public class Pictures extends Activity implements OnPageChangeListener{ SoundManager snd; int sound1,sound2,sound3; View view=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.picturespage); MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); myPager.setOnPageChangeListener(this); snd = new SoundManager(this); sound1 = snd.load(R.raw.sound1); sound2 = snd.load(R.raw.sound2); sound3 = snd.load(R.raw.sound3); } public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } public void onPageSelected(int position) { // TODO Auto-generated method stub switch (position) { case 0: snd.play(sound1); break; case 1: snd.play(sound2); break; case 2: snd.play(sound3); break; case 3: Toast.makeText(this, "1", Toast.LENGTH_SHORT).show(); break; case 4: Toast.makeText(this, "2", Toast.LENGTH_SHORT).show(); break; case 5: Toast.makeText(this, "3", Toast.LENGTH_SHORT).show(); break; } } };

    Read the article

  • ViewPager resize height to Content

    - by user1324936
    ViewPager does not wrap its height to its content. For my layout I need to set the hight then dynamically because it is nested in other layouts. Therefore I created a ScrollView as content of the ViewPager and check its height in onCreate method of the Fragment, but the ScrollView has always the same size. How can I resize the ViewPager to fit to its content? final ScrollView sv = (ScrollView) v.findViewById(R.id.sv); ViewTreeObserver vto = scrollViewMenuFragen.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { int height = sv.getMeasuredHeight(); //always same height independent of content height //need to resize ViewPager ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) mPager.getLayoutParams(); params.height = height; mPager.setLayoutParams(params); } });

    Read the article

  • Subclassing ViewPager Breaks Animation

    - by Ryan Thomas
    In my Android application I have an activity which uses a view pager to display 4+ pages (Fragments). I implemented buttons on each screen that move between pages by calling: pager.setCurrentItem(position, true); The view pager and fragments are all working as I desired. I then began looking for a solution to disable user swiping between pages so that the transition between pages in handled by the buttons only. The solution I found was mentioned in a few stackoverflow articles as well as This Blog that suggest subclassing the view pager to intercept touch events to disable swiping. I followed those examples by subclassing the view pager class as follows: public class ViewPager extends android.support.v4.view.ViewPager { private boolean enabled; public ViewPager(Context context, AttributeSet attrs) { super(context, attrs); this.enabled = true; } @Override public boolean onTouchEvent(MotionEvent event) { if (this.enabled) { return super.onTouchEvent(event); } return false; } @Override public boolean onInterceptTouchEvent(MotionEvent event) { if (this.enabled) { return super.onInterceptTouchEvent(event); } return false; } public void setSwipingEnabled(boolean enabled) { this.enabled = enabled; } } Using the subclassed view pager and calling setSwipingEnabled(false) works as was desired. The user can no longer move between pages with swipe gestures and I can still move between pages via button clicks by calling setCurrentItem(int position, boolean smoothScroll). However using the subclass breaks the animation between pages. When I call setCurrentItem(position, true) with android.support.v4.view.ViewPager I get very clean scrolling animations between pages. When I make the same call using the subclass the screen has a very brief 'flash' and then automatically draws the new page. I would like to know how to fix the animation while retaining the ability to disable user swiping between pages. I greatly appreciate any help with this. Let me know if you need any additional information. So far I have tested using a Samsung device running 2.3.5 and an AVD emulator targeting Android 2.3.3.

    Read the article

  • ViewPager and Fragment Pager adapter implementation

    - by Rohit Deshmukh
    So I am trying to implement sliding views/fragments using viewpager and fragment pager adapter. convert_home is my main xml file that has android.support.v4.view.PagerTitleStrip and temperature.xml and velocity.xml are my two other views. I have no clue where I am going wrong. package app.converto; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class ConverTo extends FragmentActivity { SectionsPagerAdapter mSectionsPagerAdapter; ViewPager mViewPager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mSectionsPagerAdapter); setContentView(R.layout.converto_home); mViewPager = (ViewPager) findViewById(R.id.pager); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.converto_home, menu); return true; } public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { switch(i){ case 0: Fragment1 fragment = new Fragment1(); return fragment; case 1: Fragment2 fragment2 = new Fragment2(); return fragment2; } defaultFragment fragment3 = new defaultFragment(); return fragment3; } @Override public int getCount() { return 2; } // // @Override // public CharSequence getPageTitle(int position) { // switch (position) { // case 0: return getString(R.string.velocity); // case 1: return getString(R.string.temperature); // case 2: return getString(R.string.distance); // } // return null; // } } public static class Fragment1 extends Fragment{ public Fragment1(){ } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //return inflater.inflate(R.layout.temperature, container, false); View view = inflater.inflate(R.layout.temperature, container, false); TextView textView = (TextView) view.findViewById(R.id.sample); textView.setText(getArguments().getString("title")); return view; } } public static class Fragment2 extends Fragment{ public Fragment2(){ } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //return inflater.inflate(R.layout.velocity, container, false); View view = inflater.inflate(R.layout.temperature, container, false); TextView textView = (TextView) view.findViewById(R.id.sample); textView.setText(getArguments().getString("title")); return view; } } public static class defaultFragment extends Fragment{ public defaultFragment(){ }//end constructor @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // return inflater.inflate(R.layout.temperature, container, false); View view = inflater.inflate(R.layout.temperature, container, false); TextView textView = (TextView) view.findViewById(R.id.sample); textView.setText(getArguments().getString("title")); return view; }//end oncreate }//end default fragment }

    Read the article

  • ActionBarSherlock + ViewPager caching more then just prev/next view

    - by miroslavign
    on the page: onCreate called for two tabs each time one tab is selected there is explained how the ABS(actually ViewPager) is working in order for ViewPager to be able to do a scrolling. It is clear that at least a prev/next page need all to be created at the same time. Would it be possible to "cache" more than just prev/next Views(Fragments), in a way: I am on Page 1 and there I have a network call to fetch some data(doing this in Activity, not in Fragment - btw. is this OK?) switch to Page 2, and then switch to Page 3, and then switch to Page 1 = Here my page is recreated (using some caching though, BUT, I do not need any recreation if possible) So, it would be nice to cache all the pages. How to accomplish this If possible in current version (4), or this would be some new feature? Or even better question, how to postpond/disable destroying of views?

    Read the article

  • Android - Temporal & Ancestral Navigation with ViewPager & Fragments

    - by rascuache
    I'm trying to work out the best way to implement the 'ancestral' and 'temporal' navigation (utilising the up button and back buttons), for a music player I'm working on. Currently, the user is presented with a viewpager, and can page between three main fragments (ArtistMain, AlbumMain and SongMain). Upon choosing an item inside that view, a fragment transaction occurs, and the viewpager goes out of view, replaced by a new fragment (AlbumSub, Songsub or player, depending on where the user came from). The user can then navigate deeper, until a song is chosen, and then they are taken to the 'player' screen. I guess the question is: How do I implement all of this conditional navigation? I'm fairly new to android and programming in general, and I just can't seem to come up with an efficient way to achieve this. At the moment, as each fragment is brought into view, the app is checking to see where the user just came from, and then determines where the user should be taken if back or home is called. This means I have a booleans like "fromArtistMain", "fromAlbumSub", and I'm checking for things like "fromSongSub && fromPlayer".. it's all turning into a bit of a mess. I've drawn a diagram (in paint, sorry!!), to depict the navigation I'm trying to achieve. The yellow represents the 'up' button press, the red is the 'back' button press, and blue is just normal navigation. The green arrows are meant to represent the view paging: Any advice is welcome. It might take something really simple that I've just overlooked. Thanks for your time.

    Read the article

  • ViewPager + recycling views?

    - by user291701
    I'd like to create a gallery of photos that swipe left and right. At first I took a look at Gallery, but it's marked as deprecated. http://developer.android.com/reference/android/widget/Gallery.html We're told to try ViewPager instead. But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it? http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html Is it up to us to build the recycling mechanism? Thanks

    Read the article

  • How do you set Android ViewPager to encompass only one View or Layout?

    - by Kyle
    I am struggling with the concepts needed to properly implement a view pager. By following some tutorials and referencing developer.android.com, I am able to get a view pager almost fully functional. The pager will flip through several text views that have been setup to say "My Message 0" through "My Message 9". The problem is that the view pager also flips the button on the bottom of the activity and the red block that is right above the button. I would like to have the view pager only cycle through the text. Would you please help me understand what I'm doing wrong? I have an activity that represents a dashboard: public class DashBoard extends FragmentActivity { private static final int NUMBER_OF_PAGES = 10; private ViewPager mViewPager; private MyFragmentPagerAdapter mMyFragmentPagerAdapter; public void onCreate(Bundle icicle){ super.onCreate(icicle); setContentView(R.layout.dashboard); mViewPager = (ViewPager) findViewById(R.id.viewpager); mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mMyFragmentPagerAdapter); } private static class MyFragmentPagerAdapter extends FragmentPagerAdapter{ public MyFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int index) { return PageFragment.newInstance("My Message " + index); } @Override public int getCount(){ return NUMBER_OF_PAGES; } } and a class for the page fragment: public class PageFragment extends Fragment { public static PageFragment newInstance(String title){ PageFragment pageFragment = new PageFragment(); Bundle bundle = new Bundle(); bundle.putString("title", title); pageFragment.setArguments(bundle); return pageFragment; } @Override public void onCreate(Bundle icicle){ super.onCreate(icicle); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle){ View view = inflater.inflate(R.layout.dashboard, container, false); TextView textView = (TextView) view.findViewById(R.id.textViewPage); textView.setText(getArguments().getString("title")); return view; } } and finally, my xml for the dashboard: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/dashbaordLabel" android:layout_width="match_parent" android:layout_height="wrap_content" > <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" /> <TextView android:id="@+id/textViewPage" android:layout_width = "match_parent" android:layout_height= "wrap_content" /> <Button android:id="@+id/newGoalButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/stringNewGoal" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:onClick="createNewGoal" /> <RelativeLayout android:id="@+id/SpaceBottom" android:layout_width="match_parent" android:layout_height="75dp" android:layout_above="@id/newGoalButton" android:background="@color/red" > </RelativeLayout> </RelativeLayout> A note about my xml, I tried wrapping the text view in some view pager tags eg: <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" > <TextView android:id="@+id/textViewPage" android:layout_width = "match_parent" android:layout_height= "wrap_content" /> </android.support.v4.view.ViewPager> But all that did was make the text view disappear from the screen, while the button and red block still cycled as in the original issue.

    Read the article

  • PagerView overlapping PagerTabStrip / PagerTitleStrip

    - by user1256169
    I've been trying for about a week to get my PagerView not to overlap the TitleStrip. I've tried absolutely everything I can think of, and one StackOverflow question that looked like the same question, had an answer that wasn't applicable. It appears that both the PagerTitleStrip and the TextView start at 0,0 (left,top) Any help would be appreciated. Note that I can't use any XML (inc Layout.xml) so it's all done programatically. Here's a full working example of my problem: package com.example.projname; import android.app.Activity; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.PagerTabStrip; import android.support.v4.view.ViewPager; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.TextView; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyPagerAdapter myPagerAdapter = new MyPagerAdapter(); PagerTabStrip myPagerTabStrip = new PagerTabStrip(this); myPagerTabStrip.setGravity(Gravity.TOP); ViewPager viewPager = new ViewPager(this); viewPager.addView(myPagerTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); viewPager.setAdapter(myPagerAdapter); setContentView(viewPager); } class MyPagerAdapter extends PagerAdapter { public final String[] Titles = { "Title One", "Title Two", "Title Three", "Title Four", "Title Five" }; @Override public int getCount() { return Titles.length; } @Override public boolean isViewFromObject(View view, Object object) { return (view == object); } @Override public CharSequence getPageTitle(int position) { return Titles[position]; } @Override public Object instantiateItem(ViewGroup container, int position) { TextView textView = new TextView(getApplicationContext()); String myString = new String("Page " + (position + 1) + "\r\n"); textView.setText(myString + myString + myString + myString + myString + myString); container.addView(textView); return textView; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } } } Edit: Adding a screenshot of the problem:

    Read the article

  • TabHost disappears after locking the phone and reopening it:

    - by Emil Adz
    I have a weird issue with my TabHost in my FragmentActivity that contains a ViewPager. The problem is that when I close my phone (press the power button) while I use my application, and then I turn back the phone and my application gets reopened, at this point my TabHost is missing. So the closing of my phone is causes the TabHost to disappear. My guess would be that I need to save my tabHost state in the saveInstanceState object, and restore it in onResume I only have no idea how it's done. here is my code for the FragmentActivity: public class TabsViewPagerFragmentActivity extends FragmentActivity implements ViewPager.OnPageChangeListener, TabHost.OnTabChangeListener { static final String TAG = TabsViewPagerFragmentActivity.class.getSimpleName(); private TabHost mTabHost; private ViewPager mViewPager; private HashMap<String, TabInfo> mapTabInfo; public ViewPagerAdapter mPagerAdapter; private TextView tvReportName, tvTabTitle; private Button bBackToParameters; private Dialog progressDialog; private SGRaportManagerAppObj application; private int numberOfTabs = 0; private Display display; public static final int POPUP_MARGIN = 6; LeftSideMenu leftSideMenu; public void NotifyTabActivityViewPagerAdapter() { mPagerAdapter.notifyDataSetChanged(); } public ViewPagerAdapter getTabActivityViewPagerAdapter() { return mPagerAdapter; } public ViewPager getTabActivityViewPager() { return mViewPager; } public void setCurrentTabTitle (String title) { tvTabTitle.setText(title); Log.d(TAG, "set tab title from activity: "+title); } /** * Maintains extrinsic info of a tab's construct */ private class TabInfo { private String tag; private Class<?> clss; private Bundle args; private Fragment fragment; TabInfo(String tag, Class<?> clazz, Bundle args) { this.tag = tag; this.clss = clazz; this.args = args; } } /** * A simple factory that returns dummy views to the Tabhost */ class TabFactory implements TabContentFactory { private final Context mContext; /** * @param context */ public TabFactory(Context context) { mContext = context; } /** (non-Javadoc) * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String) */ public View createTabContent(String tag) { View v = new View(mContext); v.setMinimumWidth(0); v.setMinimumHeight(0); return v; } } /** (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); application = SGRaportManagerAppObj.getInstance(); display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); // Inflate the layout setContentView(R.layout.tabs_screen_activity_layout); tvTabTitle = (TextView) findViewById(R.id.tvTabName); tvReportName = (TextView)findViewById(R.id.tvReportName); tvReportName.setText(application.currentReport.getName()+ " - "); bBackToParameters = (Button) findViewById(R.id.bBackToParameters); leftSideMenu = (LeftSideMenu) findViewById(R.id.leftSideMenu); applyOnClickListenerToLeftSideMenu(); findViewById(R.id.showLeftMenuButton).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); int width = d.getWidth(); View panel = findViewById(R.id.leftSideMenu); View appPanel = findViewById(R.id.appLayout); if (panel.getVisibility() == View.GONE){ appPanel.setLayoutParams(new LinearLayout.LayoutParams(width, LayoutParams.FILL_PARENT)); panel.setVisibility(View.VISIBLE); applyOnClickListenerToLeftSideMenu(); }else{ ToggleButton button = (ToggleButton) findViewById(R.id.showLeftMenuButton); button.setChecked(false); panel.setVisibility(View.GONE); } } }); // Initialise the TabHost progressDialog = DialogUtils.createProgressDialog(this, this.getString(R.string.populating_view_pager)); progressDialog.show(); if (SGRaportManagerAppObj.getInstance().parametersRepository.getParametersRepository().size() == 0) { bBackToParameters.setText(R.string.back_to_report_list); } this.initialiseTabHost(savedInstanceState); if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); //set the tab as per the saved state } // Intialise ViewPager this.intialiseViewPager(); progressDialog.dismiss(); } /** (non-Javadoc) * @see android.support.v4.app.FragmentActivity#onSaveInstanceState(android.os.Bundle) */ protected void onSaveInstanceState(Bundle outState) { outState.putString("tab", mTabHost.getCurrentTabTag()); //save the tab selected super.onSaveInstanceState(outState); } /** * Initialise ViewPager */ public void intialiseViewPager() { List<Fragment> fragments = new Vector<Fragment>(); // TabInfo tabInfo = null; if (application.getCurrentDataSource().equals(DataSource.SSRS)) { numberOfTabs = application.currentReport.getTabsList().size(); } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { numberOfTabs = application.currentReport.getODTabsList().size(); Log.d(TAG, "CURRENT REPORT FROM VIEW PAGER: "+ application.currentReport.toString()); } Log.d(TAG,"Current Tabs number from TabsViewPager activity: " +numberOfTabs); if (application.getCurrentDataSource().equals(DataSource.SSRS)) { for (int i = 0; i < numberOfTabs; i++) { Tab tempTab = application.currentReport.getTabsList().get(i); if (tempTab.getTabTemplateId() == 7) { GridFragment gridFragment = new GridFragment(tempTab); fragments.add(gridFragment); } else if (tempTab.getTabTemplateId() == 8) { NewChartFragment chartFragment = new NewChartFragment(tempTab, this); fragments.add(chartFragment); } } } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { GridFragment gridFragment = GridFragment.newInstance(tempTab.getTabId()); fragments.add(gridFragment); } else if (tempTab.getTabType().equals(ODChart.XML_CHART_ELEMENT)) { NewChartFragment chartFragment = NewChartFragment.newInstance(tempTab.getTabId()); fragments.add(chartFragment); } } } Log.d(TAG, "Current report fragments set to adapter: "+fragments.toString()); /* if (this.mPagerAdapter == null) { this.mPagerAdapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments); } else { this.mPagerAdapter.removeAllFragments(); this.mPagerAdapter.addFragmentsListToAdapter(fragments); } */ this.mPagerAdapter = new ViewPagerAdapter(super.getSupportFragmentManager(), fragments); this.mViewPager = (ViewPager)super.findViewById(R.id.pager); // this.mViewPager.setAdapter(null); this.mViewPager.setAdapter(this.mPagerAdapter); this.mViewPager.setOffscreenPageLimit(0); this.mViewPager.setOnPageChangeListener(this); Log.d(TAG, "Adapter initialized!"); } /** * Initialise the Tab Host */ public void initialiseTabHost(Bundle args) { mTabHost = (TabHost)findViewById(android.R.id.tabhost); /* //new edit if (mTabHost.getChildCount() > 0) { mTabHost.removeAllViews(); } */ mTabHost.setup(); TabInfo tabInfo = null; mapTabInfo = new HashMap<String, TabsViewPagerFragmentActivity.TabInfo>(); if (args != null) {} else { if (application.getCurrentDataSource().equals(DataSource.SSRS)) { int numberOfTabs = application.currentReport.getTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { Tab tempTab = application.currentReport.getTabsList().get(i); if (tempTab.getTabTemplateId() == 7) { //GridFragment gridFragment = new GridFragment(tempTab); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), GridFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } else if (tempTab.getTabTemplateId() == 8) { TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), NewChartFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } } } else if (application.getCurrentDataSource().equals(DataSource.SGRDL)) { int numberOfTabs = application.currentReport.getODTabsList().size(); for (int i = 0; i < numberOfTabs; i++) { ODTab tempTab = application.currentReport.getODTabsList().get(i); // Log.d(TAG,"Crashed Tab type: "+ tempTab.getTabType()); if (tempTab.getTabType().equals(ODGrid.XML_GRID_ELEMENT)) { //GridFragment gridFragment = new GridFragment(tempTab); TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), GridFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } else if (tempTab.getTabType().equals(ODChart.XML_CHART_ELEMENT)) { TabsViewPagerFragmentActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab "+String.valueOf(i)).setIndicator("Tab "+String.valueOf(i)), ( tabInfo = new TabInfo("Tab "+String.valueOf(i), NewChartFragment.class, args))); this.mapTabInfo.put(tabInfo.tag, tabInfo); } } } } // Default to first tab //this.onTabChanged("Tab1"); // mTabHost.setOnTabChangedListener(this); } /** * Add Tab content to the Tabhost * @param activity * @param tabHost * @param tabSpec * @param clss * @param args */ private static void AddTab(TabsViewPagerFragmentActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { // Attach a Tab view factory to the spec ImageView indicator = new ImageView(activity.getBaseContext()); indicator.setPadding(10, 10, 10, 10); indicator.setImageResource(R.drawable.tab_select_icon_selector); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(10, 10, 10, 10); indicator.setLayoutParams(lp); tabSpec.setIndicator(indicator); tabSpec.setContent(activity.new TabFactory(activity)); tabHost.addTab(tabSpec); } /** (non-Javadoc) * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String) */ public void onTabChanged(String tag) { //TabInfo newTab = this.mapTabInfo.get(tag); int pos = this.mTabHost.getCurrentTab(); this.mViewPager.setCurrentItem(pos); } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageScrolled(int, float, int) */ @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { // TODO Auto-generated method stub } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageSelected(int) */ @Override public void onPageSelected(int position) { // TODO Auto-generated method stub this.mTabHost.setCurrentTab(position); } /* (non-Javadoc) * @see android.support.v4.view.ViewPager.OnPageChangeListener#onPageScrollStateChanged(int) */ @Override public void onPageScrollStateChanged(int state) { // TODO Auto-generated method stub } How would one save the state of the TabHost and restore it in onResume? Any help would be very appreciated.

    Read the article

  • how can i update view when fragment change?

    - by user1524393
    i have a activity that have 2 sherlockfragment in this The first two pages display fragments with custom list views which are built from xml from server using AsyncTask. However, when the app runs, only one list view is displayed, the other page is just blank public class VpiAbsTestActivity extends SherlockFragmentActivity { private static final String[] CONTENT = new String[] { "1","2"}; TestFragmentAdapter mAdapter; ViewPager mPager; PageIndicator mIndicator; protected void onCreate(Bundle savedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); super.onCreate(savedInstanceState); setContentView(R.layout.simple_tabs); mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); mPager = (ViewPager)findViewById(R.id.pager); mPager.setAdapter(mAdapter); mIndicator = (TabPageIndicator)findViewById(R.id.indicator); mIndicator.setViewPager(mPager); mIndicator.notifyDataSetChanged(); } class TestFragmentAdapter extends FragmentPagerAdapter { private int mCount = CONTENT.length; public TestFragmentAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { switch(position) { case 0: return new customlist(); case 1: return new customlistnotuser(); default: return null; } } @Override public int getCount() { return mCount; } public CharSequence getPageTitle(int position) { return VpiAbsTestActivity.CONTENT[position % VpiAbsTestActivity.CONTENT.length].toUpperCase(); } @Override public void destroyItem(View collection, int position, Object view) { ((ViewPager) collection).removeView((View) view); } } } what can i update viewpager when change pages ? the customlistnotuser page likes customlist page but not show public class customlistnotuser extends SherlockFragment { // All static variables static final String URL = "url"; // XML node keys static final String KEY_TEST = "test"; // parent node static final String KEY_ID = "id"; static final String KEY_TITLE = "title"; static final String KEY_Description = "description"; static final String KEY_DURATION = "duration"; static final String KEY_THUMB_URL = "thumb_url"; static final String KEY_PRICE = "price"; static final String KEY_URL = "url"; private ProgressDialog pDialog; ListView list; LazyAdapterbeth adapter; XMLParser parser = new XMLParser(); public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); new getFeed().execute(); } public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View thisfragment = inflater.inflate(R.layout.dovomi, container, false); return thisfragment; } private class getFeed extends AsyncTask<Void, Void, Document> { } protected Document doInBackground(Void... params) { XMLParser parser = new XMLParser(); String xml = parser.getXmlFromUrl(URL); // getting XML from URL Document doc = parser.getDomElement(xml); // getting DOM element return doc; } protected void onPostExecute(Document doc) { ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>(); NodeList nl = doc.getElementsByTagName(KEY_TEST); // looping through all song nodes <song> for (int i = 0; i < nl.getLength(); i++) { // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nl.item(i); // adding each child node to HashMap key => value map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); map.put(KEY_Description, parser.getValue(e, KEY_Description)); map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION)); map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL)); map.put(KEY_PRICE, parser.getValue(e, KEY_PRICE)); map.put(KEY_URL, parser.getValue(e, KEY_URL)); // adding HashList to ArrayList songsList.add(map); pDialog.dismiss(); } list=(ListView)getActivity().findViewById(R.id.list); // Getting adapter by passing xml data ArrayList adapter=new LazyAdapterbeth(getActivity(), songsList); list.setAdapter(adapter); // Click event for single list row list.setOnItemClickListener(new OnItemClickListener() {

    Read the article

  • Android, FragmentActivity and prevent Swipe

    - by FIG-GHD742
    I use android.support.v4.app.FragmentActivity for create a app with multi fragment/panels that can be access by drag/swipe between different part of the app. In one of my fragment I has a zoomable view and my problem is in case I is on the zoomable view I will prevent the use for drag/swipe to a other fragment. I has try to hack into android.support.v4.view.ViewPager for get the action from on Touch event but not work. I has try all of this case but not work: (All code is a a part of subclass to android.support.v4.view.ViewPager) Case 1: // Not working @Override protected void onPageScrolled(int position, float offset, int offsetPixels) { if (isPreventDrag()) { super.onPageScrolled(position, 1, 0); } else { super.onPageScrolled(position, offset, offsetPixels); } } Case 2: // Work but stop all event include the event to the target image view. @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastX = ev.getX(); // float lockScroll = false; return super.onInterceptTouchEvent(ev); case MotionEvent.ACTION_MOVE: this.lockScroll = this.isPreventDrag(); break; } if (lockScroll) { ev.setLocation(lastX, ev.getY()); return super.onInterceptTouchEvent(ev); } else { return super.onInterceptTouchEvent(ev); } } Case 3: // Work good, but by some unknown error I can drag the screen // some pixels before this stop the event. @Override public boolean onTouchEvent(MotionEvent ev) { if (this.isPreventDrag()) { return true; } else { return super.onTouchEvent(ev); } } I want a easy way to deactivate stop or deactivate if the use is allow to switch to a other Fragment. Here is a working code for me, I don't know what error I do before. // This work for me, @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (this.isPreventDrag()) { return false; } else { return super.onInterceptTouchEvent(ev); } }

    Read the article

  • Android "first time" app user tutorial

    - by EGHDK
    I'm trying to create an opening tutorial that consists of four panes for my application, but since I'm new to Android, I want to make sure I'm considering all of my options before marking this task as "complete". I know of three ways, I can only really accomplish one. There are no requirements for this tutorial, but some "wanted features" would be a sliding action to each pane would be nice as well as the image and the bottom (navigation circles) not moving and the title on top not moving. One Way 4 separate activities and 4 separate layouts The red circled items are textViews that are centered horizontally and pushed off the top. The white circled items are imageViews that are centered horizontally and vertically. The purple circled are imageViews that are centered horizontally and pushed off the bottom. Second Way 4 fragments on one activity Fragments were difficult to learn, but the more I read about them/see tutorials on them, they seem to only really be used for tablets. Would it be a valid way to accomplish this? Third Way ViewPager? http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html I've never used this before, but I know it's an option. Final Question Which way is used more often/what's the proper way to implement this? Is there any way to only have the middle part (the image) slide in, but the title (top) and the navigation images (bottom) just change once the image slides in?

    Read the article

  • How can I create my own Android Home Screen Launcher

    - by Sam_k
    I want to know how I can create my own customised home screen for Android. I have used Viewpager to add and remove screens from the home screen, creating 5 screens as default, and then adding and removing further pages in with ViewPager. I have tried both Viewpager and PagerAdapter, as per this link. Is this the best approach so that in future I can add widgets and shortcuts with viewpager and make a launcher icon?

    Read the article

  • Better way to get int from FragmentActivity in a Fragment?

    - by Gimberg
    Hi im trying to get an int from my FragmentActivity and i have a way to do this but the code get very cluttered and long and i did this to shorten the problem and i don't get any errors while in the editor but when i run the app it eminently crashes. Any suggestions? An example of the code that doesn't work MainActivity mainActivity = ((MainActivity)getActivity()); public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.upgrades_fragment, container, false); TextView AirFreshenersCost = (TextView) view.findViewById(R.id.AirFreshenersCost ); if(mainActivity.amountAirFresheners == 5){ AirFreshenersCost.setText("5"); } return view; } LogCat 10-27 22:16:37.333: E/AndroidRuntime(5593): FATAL EXCEPTION: main 10-27 22:16:37.333: E/AndroidRuntime(5593): java.lang.NullPointerException 10-27 22:16:37.333: E/AndroidRuntime(5593): at com.free.dennisg.clickingbad.fragments.UpgradesFragment.onCreateView(UpgradesFragment.java:40) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.view.ViewPager.populate(ViewPager.java:1068) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.view.ViewPager.populate(ViewPager.java:914) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.support.v4.view.ViewPager$3.run(ViewPager.java:244) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.view.Choreographer.doCallbacks(Choreographer.java:562) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.view.Choreographer.doFrame(Choreographer.java:531) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.os.Handler.handleCallback(Handler.java:730) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.os.Handler.dispatchMessage(Handler.java:92) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.os.Looper.loop(Looper.java:137) 10-27 22:16:37.333: E/AndroidRuntime(5593): at android.app.ActivityThread.main(ActivityThread.java:5289) 10-27 22:16:37.333: E/AndroidRuntime(5593): at java.lang.reflect.Method.invokeNative(Native Method) 10-27 22:16:37.333: E/AndroidRuntime(5593): at java.lang.reflect.Method.invoke(Method.java:525) 10-27 22:16:37.333: E/AndroidRuntime(5593): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 10-27 22:16:37.333: E/AndroidRuntime(5593): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 10-27 22:16:37.333: E/AndroidRuntime(5593): at dalvik.system.NativeStart.main(Native Method) An example of the code that work public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.upgrades_fragment, container, false); TextView AirFreshenersCost = (TextView) view.findViewById(R.id.AirFreshenersCost ); if(((MainActivity)getActivity()).amountAirFresheners == 5){ AirFreshenersCost.setText("5"); } return view; }

    Read the article

  • add android support library v4 to intellij ide

    - by user1233587
    i am trying to use viewpager from android support library v4 in intelli j currently i have android sdk 4.1 I copied android-support-v4.jar to my intellij android project under 'libs' in the project settings of intellij I webt to "Modules" = "MyModuleName" = dependencies tab, and add the android-support-v4.jar, by navigating the path to the libs/ folder under my own project I checked the 'export' besides this newly added jar file but i still can't use viewpager in my application i get a crash msg like java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx/com.xxxx.MyActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class android.support.v4.view.ViewPager

    Read the article

  • Adapter for circle page indicator in android

    - by Charles LAU
    I am currently working on an android application which have multiple pages. I am trying to use Circle page indicator to allow users view multiple pages by flipping over the screen. Each page has seperate XML file for the view and each page has a button which is bind to a java method in the Activity. I would like to know how to initalise all the buttons in the Activity for multiple pages. Because at the moment, I can only initalise the button for the first page of the views. I cannot initalise the button for second and third page. Does anyone know how to achieve this. I have placed all the jobs to be done for all the buttons in a single activity. I am currently using this indicator : http://viewpagerindicator.com/ Here is my adapter for the circle page indicator: @Override public Object instantiateItem(View collection, int position) { inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int resid = 0; //View v = null;// inflater.inflate( R.layout.gaugescreen, (ViewPager)collection, false ); switch( position ) { case 0: resid = R.layout.gaugescreen; break; case 1: resid= R.layout.liveworkoutstatisticsscreen; break; case 2: resid = R.layout.mapscreen; break; default: resid = R.layout.gaugescreen; break; } View view = inflater.inflate(resid, null); ((ViewPager) collection).addView(view,0); return view; } Does anyone know how to achieve this? Thanks for any help in advance

    Read the article

  • Android image click in horizontal page view

    - by JaseemAmeer
    I've implemented horizontal page view with many images. And I'm trying to create a click event on the image. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pbase); ImageView binfo,bheacno; tvHeacno=(TextView) findViewById(R.id.tvheacno); heacno=getHeacno(); tvHeacno.setText(heacno); MyPagerAdapter adapter=new MyPagerAdapter(); ViewPager myPager=(ViewPager)findViewById(R.id.mythreepanelpager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); binfo=(ImageView) findViewById(R.id.ivinfo); bheacno=(ImageView) findViewById(R.id.ivheacno); binfo.setOnClickListener(this); bheacno.setOnClickListener(this); } then i've MyPagerAdapter class and the onclik method. it returns null to binfo and hence fails at binfo.setOnClickListener(this) I've done image click before on normal pages successfully. Is it because of horizontal page views? How can I solve this issue?? <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_weight="33" android:layout_gravity="top" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_weight="33" android:layout_gravity="center_horizontal" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivinfo" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/information" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text=" Information " /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="center_horizontal" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivheacno" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/heacno" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Get HEAC Number" /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="center_horizontal" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivpi" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/pi" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Personal Information" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="center" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivassn" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/assn" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Add Social Security Number" /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivvssn" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/vssn" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="View Social Security Number" /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivdssn" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/dssn" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Delete Social Security Number" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="bottom" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivali" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/ali" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Add Low Income" /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivvli" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/vli" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="View Low Income" /> </LinearLayout> <LinearLayout android:layout_weight="33" android:layout_gravity="left" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:gravity="center" android:layout_weight="50" android:id="@+id/ivdli" android:layout_width="wrap_content" android:layout_gravity="center" android:layout_height="wrap_content" android:src="@drawable/dli" /> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="@android:color/black" android:layout_weight="50" android:layout_gravity="center" android:gravity="center" android:text="Delete Low Income" /> </LinearLayout> </LinearLayout> </LinearLayout>

    Read the article

  • Android App crashing on one device only

    - by Daniel1402
    I am working on a new game that works perfectly on my test devices, 7-inch tablets and smartphones. But it crashes on my Galaxy Tab2 10-inch tablet with an Out of memory error. It always crashes when I start to play a second game! I have spent a full week checking the codes and I cannot figure out what is wrong. When I play from the menu screen, everything works fine. When I want to replay a game level from the level screen, the game will crash on the second launch. The level screen is made of 3 fragments, each with 32 buttons (4kB in size). I tried to keep only one fragment in memory with viewPager.setOffscreenPageLimit(1); but it does not solve the problem. Could someone stir me in some direction as to where to look for the potential problem? Why is the 10-inch tablet the only one to crash? Thanks.

    Read the article

1 2  | Next Page >