Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid view pager with page indicator
    text
    copied!<p>I need to get page indicator in the view pager file with images. Here is my code.</p> <pre><code>public class IndicatorActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MyPagerAdapter adapter = new MyPagerAdapter(); ViewPager myPager = (ViewPager) findViewById(R.id.pager); myPager.setAdapter(adapter); myPager.setCurrentItem(0); TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicat); indicator.setViewPager( myPager ); } } </code></pre> <p>In this code, i got an error in <code>TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicat);</code> as <code>TitlePageIndicator cannot be resolved to a type</code>. What is this error. How can I resolve it?</p> <p>here is my xml code:</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:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; &lt;com.viewpagerindicator.TitlePageIndicator android:id="@+id/indicat" android:layout_height="wrap_content" android:layout_width="fill_parent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>What code do I need to write in the <code>TitlePageIndicator</code>? <strong>I want to do this without using fragments</strong>.</p> <p>Me also created a class such as:</p> <pre><code>class MyPagerAdapter extends PagerAdapter { private static Integer[] titles = new Integer[] { R.drawable.jk,R.drawable.lm,R.drawable.no }; public int getCount() { return 3; } public Object instantiateItem(View collection, int position) { LayoutInflater inflater = (LayoutInflater) collection.getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view; ImageView iv; view = inflater.inflate(R.layout.first, null); ((ViewPager) collection).addView(view, 0); switch (position) { case 0: iv = (ImageView)view.findViewById(R.id.imageView1); iv.setImageResource(titles[position]); break; case 1: iv = (ImageView)view.findViewById(R.id.imageView1); iv.setImageResource(titles[position]); break; case 2: iv = (ImageView)view.findViewById(R.id.imageView1); iv.setImageResource(titles[position]); break; } return view; } public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } } </code></pre> <p>Did I want to do anything more than this class?</p> <p>Thanks in advance for help</p>
 

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