您好我的页面将使用名称图像1,2,3等运行,但图像不会出现任何想法?感谢您给予的任何帮助!!
CustomSwipeAdapter.java
package com.example.kieranbroom.nextapp1;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resources = {R.drawable.images3,R.drawable.nextclothing1,R.drawable.product,R.drawable.mens};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdapter(Context ctx)
{
this.ctx = ctx;
}
@Override
public int getCount () {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return (view==(LinearLayout)o);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflater.inflate(R.layout.swipe_layout, container, false);
ImageView imageview = (ImageView)item_view.findViewById(R.id.image_view);
TextView textView = (TextView)item_view.findViewById(R.id.image_count);
textView.setText("Image : "+position);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
activity_gallery
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
></android.support.v4.view.ViewPager>
CustomSwipeAdapter
package com.example.kieranbroom.nextapp1;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resources = {R.drawable.images3,R.drawable.nextclothing1,R.drawable.product,R.drawable. mens};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdapter(Context ctx)
{
this.ctx = ctx;
}
@Override
public int getCount () {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return (view==(LinearLayout)o);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflater.inflate(R.layout.swipe_layout, container, false);
ImageView imageview = (ImageView)item_view.findViewById(R.id.image_view);
TextView textView = (TextView)item_view.findViewById(R.id.image_count);
textView.setText("Image : "+position);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
GalleryActivity
package com.example.kieranbroom.nextapp1;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resources = {R.drawable.images3,
R.drawable.nextclothing1,
R.drawable.product,
R.drawable.mens};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdapter(Context ctx)
{
this.ctx = ctx;
}
@Override
public int getCount () {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object o) {
return (view==(LinearLayout)o);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflater.inflate(R.layout.swipe_layout, container, false);
ImageView imageview = (ImageView)item_view.findViewById(R.id.image_view);
TextView textView = (TextView)item_view.findViewById(R.id.image_count);
textView.setText("Image : "+position);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}