How to set data in viewpager using ArrayList? - java

Here, in this viewpageradapter class is using to set data, how can I set data in viewpager. I can try to implement but I don't know how can be achieving this.I also add my PhotoviewAdater and PhotoActivity. plz solve this problem.
public class PhotoViewAdapter extends PagerAdapter {
Context context;
ArrayList<Model_image> all_folder = new ArrayList<>();
int int_position;
LayoutInflater inflater;
public PhotoViewAdapter(Context context, ArrayList<Model_image> all_folder, int int_position) {
this.context=context;
this.all_folder=all_folder;
this.int_position=int_position;
}
#Override
public int getCount() {
return all_folder.get(int_position).getAll_imagepath().size();
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
#Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View viewLayout = inflater.inflate(R.layout.activity_photo_view_adapter, container,false);
imageView = (ImageView) container.findViewById(R.id.im_page);
try {
imageView.setImageResource(Integer.parseInt((all_folder.get(position).getAll_imagepath().get(int_position))));
} catch (Exception e) {
e.printStackTrace();
}
return viewLayout;
}
}
PhotoActivity:
public class PhotoActivity extends AppCompatActivity {
ViewPager viewPager;
int int_position;
PhotoViewAdapter photoViewAdapter;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo_view);
int_position = getIntent().getIntExtra("pos",0);
viewPager = (ViewPager) findViewById(R.id.imagepage);
photoViewAdapter = new PhotoViewAdapter(getApplicationContext(), ImageActivity.all_images, int_position);
viewPager.setAdapter(photoViewAdapter);
}
}
Model_image:
public class Model_image {
String str_folder;
ArrayList<String> all_imagepath;
public void setStr_folder(String str_folder)
{
this.str_folder = str_folder;
}
public void setAll_imagepath(ArrayList<String> all_imagepath)
{
this.all_imagepath = all_imagepath;
}
public String getStr_folder()
{
return str_folder;
}
public ArrayList<String> getAll_imagepath()
{
return all_imagepath;
}
}

Change this
imageView.setImageResource(all_folder[position]);
to
imageView.setImageResource(all_folder.get(position));
all_folder is defined as an Arraylist not as an array.
all_folder.get(position) returns an Model_image object.
To set the image in the imageView you need an image reference.
I dont know which image you are trying to set.
If you want to set the image from all_imagepath, try doing
imageView.setImageResource(all_folder.get(position).getAll_imagepath.get(<position of the required image>));

setImageResource is used to set an image from the apk resources.
rather use imageView.setImageBitmap(BitmapFactory.decodeFile(all_folder.get(position).getPath()));
It is unclear yet from your Model_image class what an unique path can be, so you need to define a getPath() method.

Related

Get different data via Retrofit for the Fragment in FragmentPagerAdapter for the several tablayout tabs

Conditions:
I have an Activity and I'm creating PagerAdapter extends FragmentPagerAdapter with one Fragment class. TabLayout includes 10 tabs. I have TabLayout.addOnTabSelectedListener and there in onTabSelected() I am updating some custom variable in app's SharedPreferences which depends on current tab name and tab index. Tab's names are not static - there are loading from server too.
My task:
With this value I should make a retrofit2 Call to my server and load values in adapter with recyclerview for my Fragment.
My problem:
I am loading the same data for the different tabs, which should contatin different data! I am understand that this happens because in all cases I have the same SharedPreferences variable's value so I am making retrofit Call with same conditions.
setOffscreenPageLimit() can't be setted to 0 - default is 1 according documentation:
https://developer.android.com/reference/kotlin/androidx/viewpager/widget/ViewPager#setoffscreenpagelimit;
setUserVisibleHint() on SO I've found this like some variant for solving my problem, but it can't be overrided because is deprecated now.
Solution:
I think I should save previous and next tab name in some way and then I can make different parallel retrofit Calls with different conditions. When tab selected I can get current, previous and next tab name. But how, where and when I should make two more retrofit calls?
UPD 08.02.2022: Still thinking about this problem.
Code:
SomeActivity.java
public class SomeActivity extends BaseActivity {
private String TAG="SomeActivity";
private Context context;
private TabLayout tabs;
private ViewPager viewpager;
private ProgressBar PBLoading;
private PagerAdapter_SomePAdapter adapter;
List<String> names = new ArrayList<>();
private String[] tabTitles;
public String previousTabName;
public String nextTabName;
public int counterForPreviousTabName;
public int counterForNextTabName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
context = getApplicationContext();
String categories = AppPreferences.getCategories(context);
tabTitles = categories.split(";");
tabs = findViewById(R.id.tabs);
viewpager = findViewById(R.id.viewpager);
PBLoading = findViewById(R.id.PBLoading);
tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
#Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, "onTabSelected");
AppPreferences.setCurrentValueForRetrofit(getApplicationContext(), tab.getPosition());
counterForPreviousTabName = tmpTab.getPosition() - 1;
counterForNextTabName = tmpTab.getPosition() + 1;
//here I can get tab names.
}
});
adapter = new PagerAdapter_SomePAdapter(getSupportFragmentManager(), SomeActivity.this);
viewpager.setAdapter(adapter);
adapter.updateTitleData(tabTitles);
tabs.setupWithViewPager(viewpager);
adapter.notifyDataSetChanged();
}
}
PagerAdapter_SomePAdapter.java:
public class PagerAdapter_SomePAdapter extends FragmentPagerAdapter {
int PAGE_COUNT = 2;
private String[] tabTitles = new String[] { "", ""};
private Context mContext;
Fragment_fragment fragment_fragment;
String TAG = "PagerAdapter_SomePAdapter";
public PagerAdapter_SomePAdapter(FragmentManager fm, Context context) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
mContext = context;
fragment_fragment = new Fragment_fragment();
}
#Override public int getCount() {
return PAGE_COUNT;
}
#Override public Fragment getItem(int position) {
return fragment_fragment.newInstance(position + 1, tabTitles[position]);
}
#Override public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
public void updateTitleData(String[] tabTitlesNew) {
tabTitles = tabTitlesNew;
PAGE_COUNT = tabTitlesNew.length;
notifyDataSetChanged();
}
}
Fragment_fragment.java:
public class Fragment_fragment extends Fragment {
private String TAG = "Fragment_fragment";
private static final String ARG_PAGE = "ARG_PAGE";
private int mPage;
private View rootView;
private RecyclerView RV;
private Adapter_Items adapter;
public static Fragment_fragment newInstance(int page, String tabName) {
Bundle args = new Bundle();
args.putInt(ARG_PAGE, page);
Fragment_fragment fragment = new Fragment_fragment();
fragment.setArguments(args);
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mPage = getArguments().getInt(ARG_PAGE);
}
}
#Override
public void onAttach(#NonNull Context context) {
super.onAttach(context);
mContext=context;
}
#SuppressLint("ClickableViewAccessibility")
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.content_list, container, false);
RV = rootView.findViewById(R.id.recycler_view);
new loadDataAS().execute();
return rootView;
}
private void loadData(){
//retrofit call code;
}
class loadDataAS extends AsyncTask<Void, Void, Void> {
final ProgressDialog progress = new ProgressDialog(mContext);
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Void doInBackground(Void... arg0) {
loadData();
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
adapter = new Adapter_Items(arguments, arguments2, arguments3);
RV.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}
}
Adapter_Items:
public class Adapter_Items extends RecyclerView.Adapter<Adapter_Items.ViewHolder>{
private LayoutInflater mInflater;
private Context mContext;
private static String TAG = "Adapter_Items";
public Adapter_Items(List<Integer>arguments, List<String>arguments2, List<String>arguments3){
//initializing arguments
}
// inflates the row layout from xml when needed
#NotNull
#Override
public ViewHolder onCreateViewHolder(#NotNull ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.recycle_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
//setting view's information
}
#Override
public int getItemCount() {
return arguments.size();
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
}
#Override
public void onClick(View view) {
}
}
}
First thing,
fragment should contain different data
Saving tab name after tab selected will not work. You should remove this
AppPreferences.setCurrentValueForRetrofit(getApplicationContext(),
tab.getPosition());
You should call retrofit code inside the fragment with the tabName (Not from sharedPref) to get data for that tab.
For this, make the following changes,
You are already passing the tabName to fragment instance
newInstance(int page, String tabName)
use that tabName and pass to your AsyncTask -> loadData() as
loadData(tabName);
Then you can use that in your retrofit call and get the data.
Note:
setOffscreenPageLimit()
This method will load fragments just before they are completely visible. It would be useful and a great user experience to display data directly rather than fetching only when user selects the tab.

RatingBar in fragment with ListView from Parse data

Basically I have in my Parse database two columns "rank" and "rankCount" which are both numbers.
Rank represents the total rank of the item in that row and rankCount represents the number of people who ranked it.
What I'm trying to do is create a method which will sum the average between those two, make an Int out of the number(in case its a Double/Float) and display the corresponding number with stars in a RatingBar between 1-5 stars, inside a specified Fragment with a ListView in it.
Note: I don't want to make changes in the parse database because I'm using it for the iphone version of this app witch is already complete, but I'm having a more difficult time with android.
specific Fragment class:
public class RecommendedTab extends Fragment {
ListView recommendedListView;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View tab_recommended = inflater.inflate(R.layout.tab_recommended, container, false);
recommendedListView = (ListView)tab_recommended.findViewById(R.id.recommendedList);
ParseQuery<ParseObject> query = ParseQuery.getQuery("Place");
new RemoteDataTask(){
protected void onPostExecute(List<Places> places) {
recommendedListView.setAdapter(new PlacesAdapter(getActivity(), places, null));
}
}.execute(query);
return tab_recommended;
}
}
Adapter class:
public class PlacesAdapter extends BaseAdapter{
private List<Places> places=null;
private List<Places> filteredPlaces=null;
LayoutInflater inflater;
ImageLoader imageLoader;
private Context context;
private Location loc;
public PlacesAdapter(Context context, List<Places> places, Location loc){
this.context = context;
this.places = places;
inflater = LayoutInflater.from(context);
imageLoader = new ImageLoader(context);
resetPlaces();
}
public void resetPlaces(){
filteredPlaces = places;
}
public void filter(String s){
//validation
filteredPlaces = new ArrayList<Places>();//
for(int i=0;i<places.size();i++){
if(places.get(i).getName().toLowerCase().contains(s.toLowerCase())){
filteredPlaces.add(places.get(i));
}
}
}
public class ViewHolder {
RatingBar ratingBar;
TextView name;
TextView type;
TextView adress;
TextView phone;
TextView hours;
TextView details;
ImageView image;
}
#Override
public int getCount() {
return filteredPlaces.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public Object getItem(int position) {
return filteredPlaces.get(position);
}
#Override
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.row_layout, null);
holder.name = (TextView)view.findViewById(R.id.placeName);
holder.type = (TextView) view.findViewById(R.id.placeType);
holder.image = (ImageView) view.findViewById(R.id.placeImage);
holder.ratingBar = (RatingBar)view.findViewById(R.id.placeRate);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.ratingBar.setOnRatingBarChangeListener(onRatingChangedListener(holder, position));
holder.ratingBar.setTag(position);
holder.ratingBar.setRating(places.get(position).getRatingStar());
holder.name.setText(places.get(position).getName());
holder.type.setText(places.get(position).getType());
imageLoader.DisplayImage(places.get(position).getImage(),
holder.image);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(context, PlaceDetails.class);
intent.putExtra("name", (places.get(position).getName()));
intent.putExtra("phone", (places.get(position).getPhone()));
intent.putExtra("hours", (places.get(position).getHours()));
intent.putExtra("rank", (places.get(position).getRatingStar()));
intent.putExtra("details", (places.get(position).getDetails()));
intent.putExtra("image", (places.get(position).getImage()));
context.startActivity(intent);
}
});
return view;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position) {
return new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
places.get(position).setRatingStar(v);
}
};
}
}
class for the query:
public class RemoteDataTask extends AsyncTask<ParseQuery<ParseObject>, Void, List<Places>> {
#Override
protected List<Places> doInBackground(ParseQuery<ParseObject>... query) {
List<Places> places = new ArrayList<Places>();
try {
List<ParseObject> ob = query[0].find();
for (ParseObject place : ob) {
ParseFile image = (ParseFile) place.get("image");
Places p = new Places();
p.setName((String) place.get("name"));
p.setType((String) place.get("type"));
p.setHours((String) place.get("hours"));
p.setPhone((String)place.get("phone"));
p.setDetails((String) place.get("details"));
p.setImage(image.getUrl());
places.add(p);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return places;
}
}
I have many other classes in my project but im quite sure they are irrelevant for my question.
PS: what is the android equevilant for Swift's "NSUserDefaults"?
i need to check if an item already been rated and disable the RatingBar.
There are several ways to do it, for example you can:
Add an instance variable int rank to class Place with needed setter & getter.
Using Math.round set to each Place rank rounded value of rank/rankCount, both you can get with relevant ParseObject.getDouble
And then when creating view for Place, just use it's predefined rank variable as a counter for needed stars.
Note:
it's better to use: ParseObject.getString
instead of (String) place.get("name") getting an Object and then casting to String as you did. It's also mentioned in it's Parse Documentation:
In most cases it is more convenient to use a helper function such as ParseObject.getString(String) or ParseObject.getInt(String).
Leave a comment if you need further assistance

Global Arraylist index out of range issue

I am facing an issue where I am getting ArrayIndexOutOfBound on photoViewAttacherList.get(position). Now I can easily handle by catching the error, but I am not able to understand why it is happening at the very first place. Here is the code of the adapter. It's strange because I am adding the new PhotoViewAttacher in instantiate function which will be called for every new item added.
public class FullImagePagerAdaptor extends PagerAdapter {
private final LayoutInflater inflater;
private final ArrayList<String> urls;
private final Context context;
private final ArrayList<String> descriptions;
private ArrayList<PhotoViewAttacher> photoViewAttacherList;
private TogglePagingListener togglePagingListener;
public FullImagePagerAdaptor(Context context, ArrayList<String> urls, ArrayList<String>
descriptions, TogglePagingListener togglePagingListener) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.urls = urls;
this.context = context;
this.descriptions = descriptions;
photoViewAttacherList = new ArrayList<>();
this.togglePagingListener = togglePagingListener;
}
#Override
public int getCount() {
return urls.size();
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
#Override
public Object instantiateItem(ViewGroup container, final int position) {
View v = inflater.inflate(R.layout.fragment_full_image, container, false);
TextView description = (TextView) v.findViewById(R.id.txt_full_image_description);
ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.progress_bar_full_image);
ImageView imageView = (ImageView) v.findViewById(R.id.full_image_view);
if (descriptions != null && descriptions.get(position) != null) {
description.setText(descriptions.get(position));
}
Log.d("sg","Instantiating Pager:with position" + position);
ImageUtility.loadImage(context, urls.get(position),
GlobalVariables.IMAGE_TYPE.URL, 0, 0,
imageView, progressBar);
photoViewAttacherList.add(new PhotoViewAttacher(imageView));
// THIS IS WHERE ARRAYINDEXOUTOFBOUND EXCEPTION IS GETTING RAISED
photoViewAttacherList.get(position).setOnMatrixChangeListener(new PhotoViewAttacher.OnMatrixChangedListener() {
#Override
public void onMatrixChanged(RectF rect) {
if(isImageZoomed(position))
togglePagingListener.disablePaging();
else
togglePagingListener.enablePaging();
}
});
container.addView(v);
return v;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
photoViewAttacherList = null;
container.removeView((View) object);
}
public boolean isImageZoomed(int pos) {
return checkZoom(pos) != 1.0;
}
public float checkZoom(int pos){
return photoViewAttacherList.get(pos).getScale();
}
public interface TogglePagingListener {
public void enablePaging();
public void disablePaging();
}
From your code I understand one thing that, you want to add a new PhotoViewAttacher object to your existing list and add a listener setOnMatrixChangeListener to that object.
For this you are adding that object in list and then accessing the same again from list, rather you can have an object created and add to list and to the same object you can add event listener. This is a clean approach.
position should also be recalculated to know exactly where the element was inserted but this is final so you can not change it so declare a new variable for it.
Snippet:
PhotoViewAttacher photoObj = new PhotoViewAttacher(imageView);
photoViewAttacherList.add(photoObj);
final int newPositionInserted = photoViewAttacherList.size() - 1; //Recalculating the position here to know exactly where the object was added
// Here you can use the object which was created so you do not need to worry about the index also
photoObj.setOnMatrixChangeListener(new PhotoViewAttacher.OnMatrixChangedListener() {
#Override
public void onMatrixChanged(RectF rect) {
if(isImageZoomed(newPositionInserted))
togglePagingListener.disablePaging();
else
togglePagingListener.enablePaging();
}
});

Google Glass Fullscreen Custom Layout Cards

I have an issue. Since the Card class is deprecated and the CardBuilder.EMBED_INSIDE is fairly limited. The only option is to use a custom View. I'd also like to use the CardScrollView and the CardScrollAdapter.
visit Google Glass Immersion Custom Layout without CardBuilder.Layout.EMBED_INSIDE
But my problem is, I can't have multiple views.
Here is MyCustomViewClass:
public class MyCustomView extends FrameLayout{
public MyCustomView (Context context) {
super(context);
initView();
}
private void initView()
{
View view = inflate(getContext(), R.layout.imageview, null);
addView(view);
View view2 = inflate(getContext(), R.layout.secondview, null);
addView(view2);
}
And thats my main activity class:
public class InspectionActivity extends Activity {
private CardScrollView mCardScroller;
private GestureDetector mGestureDetector;
private View mView;
private CardScrollView _cardScroller;
private ArrayList<View> _cardsList;
private MyCustomView _myView;
protected List<CardBuilder> mCards;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
createCards();
_cardsList = new ArrayList<View>();
_myView= new MyCustomView (this);
_cardsList.add(_myView);
_cardScroller = new CardScrollView(this) ;
MainCardsScrollAdapter adapter = new MainCardsScrollAdapter(_cardsList);
_cardScroller.setAdapter(adapter);
_cardScroller.activate();
setContentView(_cardScroller);
}
private void createCards() {
mCards = new ArrayList<CardBuilder>();
}
public class MainCardsScrollAdapter extends CardScrollAdapter
{
ArrayList<View> _cardsList;
public MainCardsScrollAdapter(ArrayList<View> cardsList)
{
_cardsList = cardsList;
}
#Override
public int getCount() {
return _cardsList.size();
}
#Override
public Object getItem(int i) {
return _cardsList.get(i);
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
return _cardsList.get(i);
}
#Override
public int getPosition(Object o) {
return _cardsList.indexOf(o);
}
#Override
public int getViewTypeCount() {
return CardBuilder.getViewTypeCount();
}
#Override
public int getItemViewType(int position){
return 2;//should be changed, it's just an example
}
} }
Alright so from your post I'm guessing it's only inflating one of your layouts into the CardScrollView try the following.
Create a adapter class that looks something like this
public class mainAdapter extends CardScrollAdapter {
private List<CustomCard> mCards;
private LayoutInflater inflater;
public mainAdapter(List<CustomCard> cards, LayoutInflater inf)
{
this.mCards = cards;
this.inflater = inf;
}
#Override
public int getCount() {
return mCards.size();
}
#Override
public Object getItem(int i) {
return mCards.get(i);
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
int card = mCards.get(i).getLayout();
view = inflater.inflate(card, viewGroup, false);
return view;
}
#Override
public int getPosition(Object o) {
return this.mCards.indexOf(o);
}
}
my CustomCard class looks like this, you could just use a List<Integer> instead tho
public class CustomCard {
public int getLayout() {
return layout;
}
public int layout;
public CustomCard(int layout)
{
this.layout = layout;
}
}
In your activity class create and fill a list with the desired layouts and pass them to your adapter as follows.
in the onCreate()
CreateCards();
mCardScroller = new CardScrollView(this);
mCardScroller.setAdapter(new mainAdapter(mCards, getLayoutInflater()));
and the CreateCards() method would look something like this
public void CreateCards() {
mCards.add(new CustomCard(R.layout.firstview));
mCards.add(new CustomCard(R.layout.secondview));
mCards.add(new CustomCard(R.layout.thirdview));
}
Hope this is of use for you

ListView of ONLY drawables

I have a dynamic array of drawables and want to display them in a scrollable list. The thing I am having the most trouble with is the array adapter. I don't get any compile time errors with this code, but the runtime error I get is -
Process: com.example.michael.myandroidappactivity, PID: 12297
java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
I don't want to use a textview though! Here's the main code-
public class cards extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_old_cards);
ListView list = (ListView)findViewById(R.id.showCardList);
cardPile tmp = cardPile.getInstance();
ArrayList<Integer> discardPile = tmp.getDiscardPile();
ArrayAdapter<Integer> imgAdapt = new ArrayAdapter<Integer>(this,R.layout.listview_layout,discardPile);
list.setAdapter(imgAdapt);
}
}
You have to create a new class that extends the BaseAdapter interface and modify the getView method to return the view you want to show in your ListView. For example:
public class ImageAdapter extends BaseAdapter
{
private Context context;
private ArrayList<Integer> imagesIds;
public ImageAdapter(Context _context, ArrayList<Integer> _imageIds)
{
context = _context;
imageIds = _imageIds;
}
#Override
public int getCount()
{
return imgIds.size();
}
#Override
public Object getItem(int position)
{
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
ImageView view;
if( convertView != null ) // recycle call
{
view = (ImageView) convertView;
}
else
{
view = new ImageView(context);
image.setBackgroundResource(imageIds.get(position));
}
return view;
}
}
Then modify your listView adapter as:
list.setAdapter( new ImageAdapter( this, discardPile) );

Categories