<legend id='o1fTa'><style id='o1fTa'><dir id='o1fTa'><q id='o1fTa'></q></dir></style></legend>
      1. <tfoot id='o1fTa'></tfoot>
        <i id='o1fTa'><tr id='o1fTa'><dt id='o1fTa'><q id='o1fTa'><span id='o1fTa'><b id='o1fTa'><form id='o1fTa'><ins id='o1fTa'></ins><ul id='o1fTa'></ul><sub id='o1fTa'></sub></form><legend id='o1fTa'></legend><bdo id='o1fTa'><pre id='o1fTa'><center id='o1fTa'></center></pre></bdo></b><th id='o1fTa'></th></span></q></dt></tr></i><div id='o1fTa'><tfoot id='o1fTa'></tfoot><dl id='o1fTa'><fieldset id='o1fTa'></fieldset></dl></div>

        <small id='o1fTa'></small><noframes id='o1fTa'>

        • <bdo id='o1fTa'></bdo><ul id='o1fTa'></ul>
      2. 到viewpager的左右导航不起作用

        时间:2023-10-03
          <bdo id='j2c7Y'></bdo><ul id='j2c7Y'></ul>
        • <legend id='j2c7Y'><style id='j2c7Y'><dir id='j2c7Y'><q id='j2c7Y'></q></dir></style></legend>
                1. <i id='j2c7Y'><tr id='j2c7Y'><dt id='j2c7Y'><q id='j2c7Y'><span id='j2c7Y'><b id='j2c7Y'><form id='j2c7Y'><ins id='j2c7Y'></ins><ul id='j2c7Y'></ul><sub id='j2c7Y'></sub></form><legend id='j2c7Y'></legend><bdo id='j2c7Y'><pre id='j2c7Y'><center id='j2c7Y'></center></pre></bdo></b><th id='j2c7Y'></th></span></q></dt></tr></i><div id='j2c7Y'><tfoot id='j2c7Y'></tfoot><dl id='j2c7Y'><fieldset id='j2c7Y'></fieldset></dl></div>

                  <tfoot id='j2c7Y'></tfoot>
                    <tbody id='j2c7Y'></tbody>
                2. <small id='j2c7Y'></small><noframes id='j2c7Y'>

                  本文介绍了到viewpager的左右导航不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的应用程序中使用视图寻呼机,viewpager 工作完美,但我想添加 viewpagerindicator,以下是我的片段代码和 ui 设计的 xml 任何人都可以告诉我有什么问题吗?提前谢谢.............

                  I am using view pager in my app,viewpager is working perfect but i want to add viewpagerindicator,following is my snippet code and xml of ui design can any one tell me what is issue?thanks in advance.............

                   public class Test_Pager extends Activity{
                  private String strtd;
                  String[] imgStr;
                  ImageView imageView;
                  ArrayList<String> userImgArrayList;
                  String[] myURLs;
                  /*country list*/
                  JSONArray country_list=null;
                  private ServiceHandler sh;
                  private String jsonStr;
                  private JSONObject jsonObj;
                  private String user_img;
                  private String user_pro;
                  private static String PROFILE_VIEW_URL = "";
                  private static final String USER_IMG="product_images";
                  @Override
                  protected void onCreate(Bundle savedInstanceState) {
                  
                      super.onCreate(savedInstanceState);
                      setContentView(R.layout.test_pagerss);
                      userImgArrayList = getIntent().getStringArrayListExtra("user_images");
                      ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
                         ImageAdapter adapter = new ImageAdapter(this);
                         viewPager.setAdapter(adapter);
                        // TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
                        // titleIndicator.setViewPager(viewPager);
                         leftss=(ImageView)findViewById(R.id.lefticonsss);
                         rightss=(ImageView)findViewById(R.id.righticonsss); 
                  
                       imageView = (ImageView) findViewById(R.id.full_image_view);
                       PROFILE_VIEW_URL="";
                      StrictMode.ThreadPolicy policy = new   StrictMode.ThreadPolicy.Builder().permitAll().build();
                      StrictMode.setThreadPolicy(policy);
                      sh = new ServiceHandler();
                  
                          // Making a request to url and getting response
                          jsonStr = sh.makeServiceCall(PROFILE_VIEW_URL, ServiceHandler.GET);
                  
                          Log.d("Response: ", "> " + jsonStr);
                  
                       try {
                           jsonObj = new JSONObject(jsonStr);
                  
                  
                               /*proview_business = jsonObj.getString(PROFILE_VIEW_BUSINESS);
                               proview_subcat = jsonObj.getString(PROFILE_VIEW_SUB_CATAGORY);
                               proview_mainpro = jsonObj.getString(PROFILE_VIEW_MAINPRODUCTS);
                               proview_expr = jsonObj.getString(PROFILE_VIEW_EXPERIENCE);
                               proview_cmpname = jsonObj.getString(PROFILE_VIEW_COMPANYNAME);
                               proview_website = jsonObj.getString(PROFILE_VIEW_WEBSITE);*/
                  
                              // user_img=jsonObj.getString(USER_IMG);
                  
                  
                  
                              user_img=jsonObj.getString(USER_IMG);
                              user_img = "";
                              userImgArrayList = new ArrayList<String>();//declare userImgArrayList globally like ArrayList<String> userImgArrayList;
                              JSONArray picarray = jsonObj.getJSONArray(USER_IMG);
                              for(int i=0;i< picarray.length();i++)
                              {
                                  user_img = picarray.getString(i);
                                  userImgArrayList.add(user_img);
                                  Log.d("mylog", "curent  pro pic  = " + user_img);
                              }
                  
                  
                       } catch (JSONException e) {
                           e.printStackTrace();
                       }
                  leftss.setOnClickListener(new OnClickListener() {
                  
                              @Override
                              public void onClick(View v) {
                                  // TODO Auto-generated method stub
                                  viewPager.setCurrentItem(+1,true);
                              }
                          });
                  }
                  public class ImageAdapter extends PagerAdapter {
                       Context context;
                        ImageAdapter(Context context)
                       {
                       this.context=context;
                       }
                        @Override
                        public int getCount() {
                        return USER_IMG.length();
                        }
                  
                        @Override
                          public void destroyItem(View container, int position, Object object) {
                               ((ViewPager) container).removeView((View) object);
                          }
                       @Override
                       public boolean isViewFromObject(View view, Object object) {
                       return view == ((ImageView) object);
                       }
                  
                       @Override
                          public Object instantiateItem(ViewGroup container, int position) {
                              ImageView imageView = new ImageView(context);
                              int padding = context.getResources().getDimensionPixelSize(
                                      R.dimen.activity_horizontal_margin);
                              imageView.setPadding(padding, padding, padding, padding);
                              //imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                              //Picasso.with(context).load(userImgArrayList.get(position)).into(imageView);
                              Picasso.with(context).load(userImgArrayList.get(position)).resize(200, 200) .into(imageView);
                  
                              /*for(int i=0; i<myURLs.length;i++)
                              { 
                  
                                  try {
                                      url = new URL(myURLs[i]);
                                  } catch (MalformedURLException e) {
                                      // TODO Auto-generated catch block
                                      e.printStackTrace();
                                  }
                  
                                  try {
                                      bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                                  } catch (IOException e) {
                                      // TODO Auto-generated catch block
                                      e.printStackTrace();
                                  }
                                   imageView.setImageBitmap(bmp);
                              }
                              */
                              // imageView.setImageURI(Uri.parse(imgStr[position]));
                              ((ViewPager) container).addView(imageView, 0);
                              return imageView;
                          }
                       }
                  
                    }
                  

                  我的xml

                     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="horizontal"
                  android:background="@android:color/black"
                  android:gravity="center_horizontal"
                  >
                  
                  
                  
                       <ImageView 
                      android:layout_height="wrap_content"
                      android:layout_width="wrap_content"
                  
                     android:src="@drawable/arrow"
                     android:rotation="180"
                      android:id="@+id/lefticonsss"
                      />
                  
                  
                    <android.support.v4.view.ViewPager
                    android:id="@+id/view_pager"
                    android:layout_width="150dp"
                    android:layout_height="150dp"
                  
                     />
                  
                      <ImageView android:id="@+id/full_image_view"
                      android:layout_width="wrap_content"
                  
                      android:layout_height="wrap_content"/>
                  
                  
                      <ImageView 
                      android:layout_height="wrap_content"
                      android:layout_width="wrap_content"
                      android:src="@drawable/arrow"
                  
                      android:id="@+id/righticonsss"
                      />
                  
                  
                  
                      </LinearLayout>
                  

                  推荐答案

                  我使用这个库 https://github.com/astuetz/PagerSlidingTabStrip

                  总结:

                  1. 在你的 onCreate 中执行此操作

                  1.do this in your onCreate

                  // Initialize the ViewPager and set an adapter
                  ViewPager pager = (ViewPager) findViewById(R.id.pager);
                  pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
                  
                  // Bind the tabs to the ViewPager
                  PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
                  tabs.setViewPager(pager);
                  

                  1. (可选)如果您将 OnPageChangeListenerViewPager 一起使用,则应将其设置在 Widget 而不是 ViewPager直接.

                  1. (Optional) If you use an OnPageChangeListener with your ViewPager you should set it in the Widget rather than on the ViewPager directly.

                  tabs.setOnPageChangeListener(mPageChangeListener);

                  这篇关于到viewpager的左右导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7 下一篇:SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未

                  相关文章

                    <bdo id='VQKqO'></bdo><ul id='VQKqO'></ul>
                    <tfoot id='VQKqO'></tfoot>

                    <small id='VQKqO'></small><noframes id='VQKqO'>

                  1. <legend id='VQKqO'><style id='VQKqO'><dir id='VQKqO'><q id='VQKqO'></q></dir></style></legend>
                    <i id='VQKqO'><tr id='VQKqO'><dt id='VQKqO'><q id='VQKqO'><span id='VQKqO'><b id='VQKqO'><form id='VQKqO'><ins id='VQKqO'></ins><ul id='VQKqO'></ul><sub id='VQKqO'></sub></form><legend id='VQKqO'></legend><bdo id='VQKqO'><pre id='VQKqO'><center id='VQKqO'></center></pre></bdo></b><th id='VQKqO'></th></span></q></dt></tr></i><div id='VQKqO'><tfoot id='VQKqO'></tfoot><dl id='VQKqO'><fieldset id='VQKqO'></fieldset></dl></div>