Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to change Items created with a ViewPager?
    primarykey
    data
    text
    <p>I'm rebuilding my app design and would like to use a ViewPager for it. The implementation wasn't quite the problem, but I can't figure out how to change my TextViews inside the pages. Hours of googling didn't help me either. Maybe you can help me. I simply need to know how to change the text, textcolor and stuff of my TextViews. main.xml includes my ViewPager and speiseplan.xml includes the TextViews inside a ScrollView, each with an id.</p> <p>main.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;android.support.v4.view.ViewPager android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/awesomepager" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>I won't write the whole speiseplan.xml here, since it simply includes a ScrollView and a bunch of TextViews.</p> <p>Implementation in Java is the following:</p> <pre><code>public class Speiseplan extends Activity { private ViewPager myPager; private static int NUM_VIEWS = 14; private MyPagerAdapter myAdapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myAdapter = new MyPagerAdapter(); myPager = (ViewPager) findViewById(R.id.awesomepager); myPager.setAdapter(myAdapter); } private class MyPagerAdapter extends PagerAdapter{ @Override public int getCount() { // TODO Auto-generated method stub return NUM_VIEWS; } @Override public Object instantiateItem(View collection, int position){ LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.speiseplan, null); ((ViewPager) collection).addView(view, 0); return view; } @Override public void destroyItem(View arg0, int arg1, Object arg2){ ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } } } </code></pre> <p>Now how can I access my TextViews and change them. And how can I detect the user sqiping to another page.</p> <p>Thanks for helping!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload