Android: How to format getIntent().getIntExtra - android

I am trying to retrieve the image resource file in another class, the intent putExtra has been placed in the MainActivity but I'm not sure how to retrieve that in the other class? I've tried getIntent().getIntExtra("category", search_name); but I just get errors. The idea is that the user claiks on the photo of a recipe category and then in the other class I can match that resource image file to the category name and retrieve the corresponding recipes.
Also this gridview slows down the app, how would I wrap and call this in an Async?
MainActivity
GridView gv = findViewById(R.id.gridview);
gv.setAdapter(new SetImageAdapter(this));
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent = new Intent(MainActivity.this, Category.class);
intent.putExtra("Category", SetImageAdapter.categories[position]); // put image data in Intent
startActivity(intent); // start Intent
}
});
GridView Adapter
package com.stu54259.plan2cook;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class SetImageAdapter extends BaseAdapter {
public static Integer[] categories = {
R.drawable.african, R.drawable.american,
R.drawable.asian, R.drawable.comfort,
R.drawable.desserts, R.drawable.greek,
R.drawable.italian, R.drawable.vegetarian,
R.drawable.mexican,
};
private Context Cont;
public SetImageAdapter(Context c) {
Cont = c;
}
public int getCount() {
return categories.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgview = new ImageView(Cont);
imgview.setLayoutParams(new GridView.LayoutParams(370, 250));
imgview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imgview.setPadding(10,10,10, 10);
imgview.setImageResource(categories[position]);
return imgview;
}
}

In your MainActivity :
GridView gv = findViewById(R.id.gridview);
gv.setAdapter(new SetImageAdapter(this));
gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Intent intent = new Intent(MainActivity.this, Category.class);
intent.putExtra("CategoryPosition", position); // put image data in Intent
startActivity(intent); // start Intent
}
});
In your Category activity :
int position = getIntent().getIntExtra("CategoryPosition",0);
int selectedDrawable = SetImageAdapter.categories[position];
//Get name of the selected drawable :
String search_name = getResources().getResourceEntryName(selectedDrawable);
The possibility reason why the performance of your GridView is slow is the drawable resource size, make sure that all image used has a small resolution as well as smaller size.

Related

how to show full size image on clicking thumbnail in gridview

In my project i want that whenever anyone clicks on thumbnail , full size image should open in an activity which user can zoom . but facing problem in passing the url of image (i used arraylist).
below is the code
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import java.util.ArrayList;
public class NoticeList_Seminar extends AppCompatActivity {
GridView gridView;
ArrayList<Notice_Activity_Seminar> list;
Notice_List_Adapter_Seminar adapter_seminar = null;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.noticelistlayout_seminar);
gridView = (GridView) findViewById(R.id.gridView);
list = new ArrayList<>();
adapter_seminar = new Notice_List_Adapter_Seminar(NoticeList_Seminar.this, R.layout.noticeitemslayout_seminar, list);
gridView.setAdapter(adapter_seminar);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//Intent intent = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
//intent.putExtra("id",i);
//startActivity(intent);
Toast.makeText(getApplicationContext(),"full image", Toast.LENGTH_SHORT).show();
}
});
Cursor cursor = App_Activity_Seminar.sqLiteHelper_seminar.getData("SELECT * FROM NOTICE_SEMINAR");
list.clear();
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String name = cursor.getString(1);
String date = cursor.getString(2);
byte[] image = cursor.getBlob(3);
list.add(new Notice_Activity_Seminar(id, name, date, image));
}
adapter_seminar.notifyDataSetChanged();
}
}
code for FullImage activity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import static com.example.shakshi.demo.R.id.imageView;
public class FullImageActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int pos = i.getIntExtras("position",0);
imageView.setImageResource(Notice_List_Adapter_Seminar.noticeList[pos]);
/* Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
Notice_List_Adapter_Seminar imageAdapter = new
Notice_List_Adapter_Seminar(FullImageActivity.this);
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(Notice_List_Adapter_Seminar.noticeList[position]);
}
}
changes i have done
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int
i, long l) {
String url = String.valueOf(adapterView.getItemAtPosition(i));
Intent intent = new Intent(NoticeList_Workshop.this,
FullImageActivity.class);
intent.putExtra("url", url);
startActivity(intent);
}
});
in Full Image Activity
String url = getIntent().getExtras().getString("url");
ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(Integer.parseInt(url));
Use gridViewOnClickListener and Intent.
GridView grdview = (GridView) findViewById(R.id.gridview);
grdview.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String url = list.get(position);
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("url", url);
startActivity(intent)
}
});
In SecondActivity onCreate() method,
String url = getIntent().getExtras().getString("url");
Set the Source of Imageview = url;
If you are using Gridview. You get onItemClickListener which also gives you the position of the item which got clicked. So in your onItemClickListener you can get the image url from the arraylist at that position and pass it to your next activity.
And if you are using Recyclerview then you can use callback pattern and using that you can send the same url as a String on which the user has clicked to the containing activity. You can then pass this url to the next activity.

Adding onClickListener to specific items in ListView

please I'm trying to add understand how to add onItemClickListener to the followng code such that when "Smartphone Plans" is clicked, its activity starts and so on. I've seen other questions on StackOverflow relating to this question but do not understand how to go about them.
I've already added an onItemClickListener but do not understand how to set it to specific list items.
here is the code
package devchuks.com.rechargeit;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.app.ListActivity;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class EtisalatData extends AppCompatActivity {
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_etisalat_data);
listView = (ListView) findViewById(R.id.list);
String[] values = new String[] {
"Smartphone Plans",
"Internet Bundles",
"Weekend Plans",
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
}
You can define your listView.setOnItemClickListener like this to go to different activity for clicking different element.
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String item = listView.getItemAtPosition(position);
Toast.makeText(this,"You selected : " + item,Toast.LENGTH_SHORT).show();
if(position==0) {
// Do your code for clicking "Smartphone Plans" example
// startActivity(new Intent(getApplicationContext(),SmartphonePlans.class));
}
else if(position==1) {
// Do your code for clicking "Internet Bundles". example
// startActivity(new Intent(getApplicationContext(),InternetBundles.class));
}
else if(position==2) {
// Do your code for clicking "Weekend Plans". example
//startActivity(new Intent(getApplicationContext(),WeekendPlans.class));*/
}
});
onItemClick will be called whenever any of the list items are clicked. The position will be the position of the view in the Adapter.
Please refer -
How to handle the click event in Listview in android?
Thanks
Sriram
try this:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String text = values[position];
if(text.equals("Smartphone Plans")){ //your specific list item text
Intent i = new Intent(MainActivity.this, AnotherActivity.class);
i.putExtra("TEXT", text);
startActivity(i);
}
}
}
If this helps and is your concern
`
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String data = values[position];
switch(data){
case "Smartphone Plans":
// do somwthing
break;
// similarly for other two values.
}
}
});`
Below method give you a position of a clicked row. Take advantage of that and value from your array.
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Move your values array to member array or make it final to use
// in Anonymous class
final String selectedValue = values[position];
Intent intent = null
// Now add case and start activity
if("Smartphone Plans".equals(selectedValue)) {
intent = new Intent(EtisalatData.this, SmartPhonePlan.class);
}
else if("other Plans".equals(selectedValue)){
// other action
}
//... more cases and at the end start your activity if its not null
startActivity(intent);
}

How do I create an interactive GridView using Picasso for Android?

Hi I'm trying to create a GridView using images from an online depository using Picasso.
I also want the user to be able to click on the image and it load up full screen to view.
So far I have managed to get it working almost perfectly. The only problem is the image that shows when they click on the grid is not the one that they clicked on, in fact it randomly chooses an image each time.
I was hoping somebody could take a look at my code and tell me where I am going wrong.
Thanks.
So this is my MainActivity class:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gv = (GridView) findViewById(R.id.grid_view);
gv.setAdapter(new GridViewAdapter(this));
gv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image id to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
}
}
This is my GridView class:
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static android.widget.ImageView.ScaleType.CENTER_CROP;
final class GridViewAdapter extends BaseAdapter {
final Context context;
final List<String> urls = new ArrayList<String>();
public GridViewAdapter(Context context) {
this.context = context;
// Ensure we get a different ordering of images on each run.
Collections.addAll(urls, Info.URLS);
Collections.shuffle(urls);
// Triple up the list.
ArrayList<String> copy = new ArrayList<String>(urls);
urls.addAll(copy);
urls.addAll(copy);
}
#Override public View getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
view.setScaleType(CENTER_CROP);
}
// Get the image URL for the current position.
String url = getItem(position);
// Trigger the download of the URL asynchronously into the image view.
Picasso.with(context) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit() //
.into(view);
return view;
}
#Override public int getCount() {
return urls.size();
}
#Override public String getItem(int position) {
return urls.get(position);
}
#Override public long getItemId(int position) {
return position;
}
}
And finally my FullScreen Class:
import com.squareup.picasso.Picasso;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class FullImageActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
GridViewAdapter ia = new GridViewAdapter(this);
ImageView iv = (ImageView) findViewById(R.id.full_image_view);
Picasso.with(this) //
.load(ia.getItem(position)) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit()
.centerCrop()//
.into(iv);
}
}
I believe this is your culprit:
Collections.addAll(urls, Info.URLS);
Collections.shuffle(urls); // this reshuffles on every new instance
GridViewAdapter ia = new GridViewAdapter(this); // your full screen activity is creating a new instance.
Since I cannot comment yet, the answer is No. When you say startActivity, it will create a new instance of the FullScreenActivity, and then in that FullScreenActivity you are also instantiating a new Adapter which in turn does the shuffle work.
Please put in a breakpoint if you are in doubt.
You reinitialized the adapter for whatever reason here GridViewAdapter ia = new GridViewAdapter(this); That's when the shuffling occurs, in the constructor.
You should not have an adapter in your 2nd Activity. Adapters are for lists. You should simply pass that Activity the image URL.
GridView gv = (GridView) findViewById(R.id.grid_view);
GridViewAdapter adapter = new GridViewAdapter(this);
gv.setAdapter(adapter);
gv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// Sending image url to FullScreenActivity
Intent i = new Intent(getApplicationContext(), FullImageActivity.class);
i.putExtra("url", adapter.getItem(position));
startActivity(i);
}
});
and
public class FullImageActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_image);
// get intent data
Intent i = getIntent();
string url = i.getExtras().getString("url");
ImageView iv = (ImageView) findViewById(R.id.full_image_view);
Picasso.with(this) //
.load(url) //
.placeholder(R.drawable.placeholder) //
.error(R.drawable.error) //
.fit()
.centerCrop()//
.into(iv);
}
}
You are creating an adapter twice - once in MainActivity, second time in FullImageActivity. Each time it is created shuffled, that's the reason. Nice copy-paste from Picasso sample btw ;)

Simplify my ListView (with Intent, setOnItemClick etc)

I write a activity with a ListView. Now I want to know, is it possible to simplify my code (make it shorter).
An example is under the codeblock
package de.bodprod.dkr;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class MediMenue extends ListActivity {
ArrayList<HashMap<String, Object>> medi_menue_items;
LayoutInflater inflater;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.medi_menue);
ListView antidotListView = (ListView) findViewById(android.R.id.list);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
medi_menue_items = new ArrayList<HashMap<String,Object>>();
HashMap<String , Object> item = new HashMap<String, Object>();
item.put("title", "Antidots");
item.put("desc", "Toxine und die Gegenmittel");
item.put("class_open", "MediAntidotList");
medi_menue_items.add(item);
item = new HashMap<String, Object>();
item.put("title", "Notfallmedikamente");
item.put("desc", "Dosierungen, Gegenanzeigen u.v.m.");
item.put("class_open", "MediNotmediList");
medi_menue_items.add(item);
ListView lv;
lv = (ListView) findViewById(android.R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent in = new Intent();
String class_open = ((TextView) view.findViewById(R.id.class_open)).getText().toString();
if(class_open.equals("MediAntidotList")){
in = new Intent(getApplicationContext(), MediAntidotList.class);
}else if(class_open.equals("MediNotmediList")){
in = new Intent(getApplicationContext(), MediNotmediList.class);
}
startActivity(in);
}
});
final CustomAdapter adapter = new CustomAdapter(this, R.layout.medi_menue, medi_menue_items);
antidotListView.setAdapter(adapter);
}
private class CustomAdapter extends ArrayAdapter<HashMap<String, Object>>{
public CustomAdapter(Context context, int textViewResourceId, ArrayList<HashMap<String, Object>> Strings) {
super(context, textViewResourceId, Strings);
}
private class ViewHolder{
TextView class_open, title, desc;
}
ViewHolder viewHolder;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=inflater.inflate(R.layout.medi_menue_item, null);
viewHolder=new ViewHolder();
viewHolder.class_open=(TextView) convertView.findViewById(R.id.class_open);
viewHolder.title=(TextView) convertView.findViewById(R.id.medi_menue_name);
viewHolder.desc=(TextView) convertView.findViewById(R.id.medi_menue_desc);
convertView.setTag(viewHolder);
}else{
viewHolder=(ViewHolder) convertView.getTag();
}
viewHolder.class_open.setText(medi_menue_items.get(position).get("class_open").toString());
viewHolder.title.setText(medi_menue_items.get(position).get("title").toString());
viewHolder.desc.setText(medi_menue_items.get(position).get("desc").toString());
return convertView;
}
}
}
For example: In the OnItemClickListener I get the id from the list item, and than I use with if and else. But the id is the same like the name from the activity, is it possible to say the new Intent, that it should open the class with the name wich is in the String class_open? Something like this:
String class_open = ((TextView) view.findViewById(R.id.class_open)).getText().toString();
Intent in = new Intent(getApplicationContext(), <class_open>.class);
startActivity(in);
First of all, since you are using ListActivity, you don't need to call setOnListItemClick handler on the list itself, just override this method from the ListActivity:
protected void onListItemClick(ListView l, View v, int position, long id);
So you can have this:
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent in = new Intent();
String class_open = ((TextView)v.findViewById(R.id.class_open)).getText().toString();
if(class_open.equals("MediAntidotList")){
in = new Intent(getApplicationContext(), MediAntidotList.class);
}else if(class_open.equals("MediNotmediList")){
in = new Intent(getApplicationContext(), MediNotmediList.class);
}
startActivity(in);
}
Then to answer your other question, you can try the Java reflection to get a class:
String class_open = ((TextView)view.findViewById(R.id.class_open)).getText().toString();
Class c = Class.forName("com.yourpackagename." + class_open );
Intent in = new Intent(getApplicationContext(), c);
I'm going for a long shot here since I haven't tried this myself. But I see you got a ViewHolder class that you don't show. If you really want to change ur onItemClick code, you could store an intent in every ViewHolder, which is set in your getView(...). This way you can get the viewholder tag in onItemClick and get the intent from that tag and start it.
Example:
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
// Get the intent that u stored in this viewholder
ViewHolder clicked = (ViewHolder)view.getTag();
Intent toStart = clicked.getIntent();
startActivity(toStart);
}
And you dont need to set the onItemClick listener since you are extending from ListActivity, just override it.
To implement all this, you need to do some changes in getView() in your adapter. I'm sure you can figure out what!

values arent being passed to intent

Stack Trace
Picture of stack trace here
Values aren't being passed to the other intent. Every time I try to start the activity with the intent in it, it crashes.
//This activity will retrieve and display the different rewards that are available.
public class RewardsActivity extends Activity {
#Override
public void onCreate(Bundle SavedInstanceState)
{
super.onCreate(SavedInstanceState);
setContentView(R.layout.rewards);
//stores retrieves and stores the current gridview
GridView gridView = (GridView)findViewById(R.id.grid_view);
//Instance of ImageAdapter class that will load the images into the gridview
gridView.setAdapter(new ImageAdapter(this));
//This function is used to set a listener on each item in the grid so that when its clicked it will go to the other view.
gridView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v,int position, long id)
{
Intent i = new Intent(getApplicationContext(),RewardsViewActivity.class);
i.putExtra("id", position);
startActivity(i);
}
});
}
This new intent is being passed to, when it's passed here it is stored in a variable then used in a ImageView to load an image.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class RewardsViewActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_view);
// get intent data
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView = (ImageView) findViewById(R.id.full_image);
imageView.setImageResource(imageAdapter.finalImages[position]);
}
}
ImageAdapter.java
package org.android.pps;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
/*This class will be used handle the loading of the image view that will display all the
images of the rewards. (this will be used along with RewardsActivity and rewards.xml)
*/
public class ImageAdapter extends BaseAdapter {
//variable that will store the current context of the application
private Context c;
private Integer num = 6;
private int[] rewards_num=new int[num];
private Integer[] Images = new Integer[6];
public Integer[] finalImages;
//for loop will set the correct image to the array if its either activated or deactivated
public Integer[] fillImageArray()
{
//Array that will be used to show the reward images
Integer[] Activated ={
R.drawable.rewards1,
R.drawable.rewards2,
R.drawable.rewards3,
R.drawable.rewards4,
R.drawable.rewards5,
R.drawable.rewards6,
};
Integer[] Deactivated ={
R.drawable.rewards1b,
R.drawable.rewards2b,
R.drawable.rewards3b,
R.drawable.rewards4b,
R.drawable.rewards5b,
R.drawable.rewards6b,
};
//for loop that checks to see all the rewards that a particular users has to assign a particular image.
for(int x = 0;x<rewards_num.length;x++)
{
for(int y = 0;y<6;y++)
{
if(rewards_num[x]==y)
{
Images[x]=Activated[y];
}
else
{
Images[x]=Deactivated[y];
}
}
}
return Images;
}
//constructor with the context being passed.
public ImageAdapter(Context m)
{
c = m;
}
public int getCount() {
return 6;
}
public Object getItem(int position) {
return Images[position];
}
public long getItemId(int position) {
return 0;
}
// The function View create a new ImageView for each item that is being referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
finalImages = fillImageArray();
ImageView imageView = new ImageView(c);
imageView.setImageResource(finalImages[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(300, 300));
return imageView;
}
}
finalImages in noi initialized there .........
it is finalImages in the getview which is not get called in 2nd activity (RewardsViewActivity )...........
if possible move this line to constructor finalImages = fillImageArray();

Categories

Resources