Android. Pager adapter and gridView. OnItemClickMetod - java

I', trying to have simple PagerAdapter with horizontal scrolling in my Android application. I try to have a grid with images in the pages. What is the simplest way to achive that?
I try something like this(It doesn't work, :
It's my MainActivity.onCreate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createHeroList();
LayoutInflater inflater = LayoutInflater.from(this);
List<View> pages = new ArrayList<View>();
View page = inflater.inflate(R.layout.page, null);
pages.add(page);
page = inflater.inflate(R.layout.page, null);
pages.add(page);
page = inflater.inflate(R.layout.page, null);
pages.add(page);
SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(1);
setContentView(viewPager);
initImageLoader(getApplicationContext());
}
It's my Image adapter
public class ImageAdapter extends BaseAdapter {
ImageLoader imageLoader = ImageLoader.getInstance();
private Context mContext;
ArrayList<String> HeroList;
String[] imageUrls;
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error).cacheInMemory()
.cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();
if (convertView == null) {
grid = new View(mContext);
// LayoutInflater inflater = getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
grid = inflater.inflate(R.layout.cellgrid, parent, false);
} else {
grid = (View) convertView;
}
ImageView imageView = (ImageView) grid.findViewById(R.id.imagepart);
TextView textView = (TextView) grid.findViewById(R.id.textpart);
imageLoader.displayImage(imageUrls[position], imageView, options);
textView.setText(HeroList.get(position));
return grid;
}
}
and my PagerAdapter.
public class SamplePagerAdapter extends PagerAdapter{
List<View> pages = null;
ArrayAdapter<String> adapter;
ArrayList<String> NamesList = new ArrayList<String>();
int HeroCount = 98;
ImageLoader imageLoader = ImageLoader.getInstance();
String[] imageUrls;
public SamplePagerAdapter(List<View> pages){
this.pages = pages;
}
#Override
public Object instantiateItem(View collection, int position){
View v = pages.get(position);
GridView gridview = (GridView) v.findViewById(R.id.gridview);
Resources myResources = v.getResources();
imageUrls = myResources.getStringArray(R.array.Urls);
gridview.setAdapter(new ImageAdapter(v.getContext()));
gridview.setOnItemClickListener(gridviewOnItemClickListener);
((ViewPager) collection).addView(v, 0);
return v;
}
private GridView.OnItemClickListener gridviewOnItemClickListener = new GridView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
// Sending image id to FullScreenActivity
Intent i = new Intent(v.getContext(),
HeroInformation.class);
i.putExtra("HeroName", NamesList.get(position));
i.putExtra("HeroUrl", imageUrls[position]);
i.putExtra("HeroNum", position);
startActivity(i);
}
};
}

Related

Error when creating Linear layout in java and passing its id it to viewpager adapter. Throwing RESOURCE NOT FOUND EXCEPTION

Here is my source code. Here I am creating Layouts and adding text view to layouts. I am putting all layout ids in an arraylist and passing it to customviewpager adapter.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
ArrayList<Integer> arrayList = new ArrayList<Integer>(3);
LinearLayout rlayout = new LinearLayout(this);
LinearLayout.LayoutParams rParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
rlayout.setId(R.id.rid);
rlayout.setLayoutParams(rParams);
TextView rtext = new TextView(this);
rtext.setText("hello");
rtext.setId(R.id.rtext);
rtext.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
rlayout.addView(rtext);
LinearLayout blayout = new LinearLayout(this);
LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
blayout.setId(R.id.bid);
blayout.setLayoutParams(bParams);
TextView btext = new TextView(this);
btext.setText("helo");
btext.setId(R.id.btext);
btext.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
blayout.addView(btext);
LinearLayout glayout = new LinearLayout(this);
LinearLayout.LayoutParams gParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
glayout.setId(R.id.gid);
TextView gtext = new TextView(this);
gtext.setText("hello");
gtext.setId(R.id.gtext);
glayout.setLayoutParams(gParams);
gtext.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
glayout.addView(gtext);
arrayList.add(0,R.id.bid);
arrayList.add(1,R.id.rid);
arrayList.add(2,R.id.gid);
viewPager.setAdapter(new CustomPagerAdapter(this,arrayList));
}
}
Here is the View pager adapter.Here I am receiving the resource Ids and inflating the layouts and casting it to viewgroup. But I am getting resource not found exception.
public class CustomPagerAdapter extends PagerAdapter {
private Context mContext;
private ArrayList <Integer> viewList;
public CustomPagerAdapter(Context context, ArrayList arrayList) {
mContext = context;
viewList = arrayList;
}
#Override
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = LayoutInflater.from(mContext);
ViewGroup layout = (ViewGroup)
inflater.inflate(viewList.get(position), collection, false);
collection.addView(layout);
return layout;
}
#Override
public void destroyItem(ViewGroup collection, int position, Object
view) {
collection.removeView((View) view);
}
#Override
public int getCount() {
return viewList.size();
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}

adding url to list view

I am creating an app in android studio.
I need to update the list view with a new url that is sent via text message.
How do I add the new url to my list?
This is what I currently have for my main code.
public class MainActivity extends AppCompatActivity {
ListView list;
WebView webView;
ArrayList<String> sites = new ArrayList<>("https://www.google.com", "https://www.yahoo.com", "https://www.apple.com");
String [] url = {"https://www.google.com", "https://www.yahoo.com", "https://www.apple.com"};
MyBroadcastReceiver receiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView)findViewById(R.id.listview);
MyListAdapter adapter = new MyListAdapter(this, sites);
sites.add("new site");
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
list.setDividerHeight(5);
webView = (WebView)findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient(){});
list.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id){
Toast.makeText(getApplicationContext(), sites.get(position), Toast.LENGTH_SHORT).show();
webView.loadUrl("https://www.google.com");
webView.loadUrl(url[position]);
}
});
receiver = new MyBroadcastReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
registerReceiver(receiver,filter);
}
}
This is myAdapterList:
public class MyListAdapter extends ArrayAdapter<String> {
private Activity context_;
private ArrayList<String> sites;
//constructor
public MyListAdapter(Activity context, ArrayList<String> sites){
super(context,R.layout.row,sites);
context_ = context;
this.sites = sites;
}
public View getView (int position, View convertView, ViewGroup parent){
if(convertView == null){
LayoutInflater inflater = context_.getLayoutInflater();
convertView = inflater.inflate(R.layout.row,null);
}
ViewHolder holder = (ViewHolder) convertView.getTag();
if(holder == null){
holder = new ViewHolder(convertView);
holder.tv_link.setText(sites.get(position));
}
else{
holder.tv_link.setText(sites.get(position));
}
return convertView;
}
private class ViewHolder{
TextView tv_link;
public ViewHolder(View row){
tv_link = (TextView) row.findViewById(R.id.tv_link);
}
}
}

ListView with image and text from JSON using ArrayAdapter

I know to get the ListItem from:
string[] = {"data1","data","data3"};
But how do I get it from a JSON response? I moved my data to:
ArrayList<HashMap<String, String>>
My code is below, I have to use JSON instead of getting a String[] because my JSON response contains an id, a title and an image link.
public class MainActivity extends AppCompatActivity {
String[] titles,header;
ListView list1;
int[] img;
String[] title;
int[] img = {R.drawable.img1, R.drawable.img2,R.drawable.img3};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list1 = (ListView) findViewById(R.id.list);
title ={"data1","data2","data3"}
myAdapter adapter = new myAdapter(getApplicationContext(), titles, img);
list1.setAdapter(adapter);
}
class myAdapter extends ArrayAdapter<String> {
Context context;
int[] imgs;
String[] titles;
private ArrayList<String> mData = new ArrayList<>();
private ArrayList<Integer> mImage = new ArrayList<>();
private TreeSet<Integer> sectionHeader = new TreeSet<Integer>();
private LayoutInflater mInflater;
myAdapter(Context context, String[] titles, int imgs[]) {
super(context, R.layout.list_item, R.id.text, titles);
this.context = context;
this.imgs = imgs;
this.titles = titles;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.list_item, parent, false);
holder.myImage = (ImageView) convertView.findViewById(R.id.image);
holder.myText = (TextView) convertView.findViewById(R.id.texttitle);
Picasso.with(context)
.load(imgs[position])
.fit()
.into(holder.myImage);
holder.myText.setText(titles[position]);
convertView.setTag(holder.myImage);
return convertView;
}
public class ViewHolder {
public TextView myText;
public ImageView myImage;
}
}
}
First change your above code by below so that you can see the list of image and string properly:
public class MainActivity extends AppCompatActivity {
ListView list1;
String[] title = {"data1", "data2", "data3"};
;
int[] img = {R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list1 = (ListView) findViewById(R.id.list);
myAdapter adapter = new myAdapter(getApplicationContext(), title, img);
list1.setAdapter(adapter);
}
}
class myAdapter extends ArrayAdapter<String> {
Context context;
int[] imgs;
String[] titles;
private ArrayList<String> mData = new ArrayList<>();
private ArrayList<Integer> mImage = new ArrayList<>();
private TreeSet<Integer> sectionHeader = new TreeSet<Integer>();
private LayoutInflater mInflater;
myAdapter(Context context, String[] titles, int imgs[]) {
super(context, R.layout.list_item, R.id.text, titles);
this.context = context;
this.imgs = imgs;
this.titles = titles;
mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int rowType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.list_item, parent, false);
holder.myImage = (ImageView) convertView.findViewById(R.id.image);
holder.myText = (TextView) convertView.findViewById(R.id.texttitle);
holder.myImage.setImageResource(imgs[position]);
// Picasso.with(context)
// .load(imgs[position])
// .fit()
// .into(holder.myImage);
holder.myText.setText(titles[position]);
convertView.setTag(holder.myImage);
}
return convertView;
}
public class ViewHolder {
public TextView myText;
public ImageView myImage;
}
}

Array Adapter doesn't call GetView

I have
public class MainActivity extends FragmentActivity
I wrote Loader class which implements AsyncResponse:
public class Loader implements AsyncResponse {
public Activity contextActivity;
Loader(Activity context) {
this.contextActivity = context;
}
Class "Loader" has method "DrawTabInfo" which calling from AsyncResponse callback.
public void drawTabInfo(String jsonBlob, int tabId)
{
JSONObject dataJsonObj;
PullToRefreshListView list = null;
try {
dataJsonObj = new JSONObject(jsonBlob);
JSONArray jsonData = dataJsonObj.getJSONArray("steals");
ArrayList<JSONObject> data = new ArrayList<JSONObject>();
for (int i=0;i<jsonData.length();i++){
data.add(jsonData.getJSONObject(i));
}
Adapter adapter = new Adapter(contextActivity, data);
LayoutInflater inflater = LayoutInflater.from(contextActivity);
if (tabId == 0) {
View view = inflater.inflate(R.layout.listviewlayout, null, false);
list = (PullToRefreshListView) view.findViewById(R.id.listView);
}
if (tabId == 1) {
View view = inflater.inflate(R.layout.listviewlayout2, null, false);
list = (PullToRefreshListView) view.findViewById(R.id.listView2);
}
list.setAdapter(adapter);
adapter.setNotifyOnChange(true);
Log.d("COUNT") shows - "4", what means array is built fine.
public class Adapter extends ArrayAdapter<JSONObject> {
private final Activity context;
private final ArrayList<JSONObject> profiles;
public String header;
public String preText;
public String imageURL;
static class ViewHolder {
public TextView header;
public ImageView image;
public TextView preText;
public LinearLayout linearItemLayout;
}
public Adapter(Activity context, ArrayList<JSONObject> array) {
super(context, R.layout.tab1_list_layout, array);
Log.d("ADAPTER", "SETTING ADAPTER");
this.context = context;
this.profiles = array;
Log.d("COUNT", "" + profiles.size());
}
#Override
public int getCount()
{
return profiles.size();
}
My getView method:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
Log.i("GetView Log", "Adapters GetView hasbeen called");// thats never calling
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.tab1_list_layout, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.linearItemLayout = (LinearLayout) rowView.findViewById(R.id.linearItemLayout);
viewHolder.header = (TextView) rowView.findViewById(R.id.itemHeader);
viewHolder.image = (ImageView) rowView.findViewById(R.id.itemPreImage);
viewHolder.preText = (TextView) rowView.findViewById(R.id.itemPreText);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
JSONObject item = null;
try {
item = profiles.get(position);
header = item.getString("header");
preText = item.getString("previewText");
imageURL = item.getString("previewImageUrl");
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("ADAPTER LOG", header);
holder.header.setText(header);
holder.preText.setText(preText);
int headerHeight = (int) Math.round(header.length() * 1.5);
holder.linearItemLayout.setMinimumHeight(40 + headerHeight + preText.length());
Picasso.with(context).setIndicatorsEnabled(true);
Picasso.with(context).load(imageURL).resize(140,100).into(holder.image);
return rowView;
}
In MainActivity i calling, where "this" = MainActivity;
Loader loader = new Loader(this);
loader.loadTabInfo(0);
Method getView never calling. What I'am doing wrong?
UPD:
Solved:
public void drawTabInfo(String jsonBlob, int tabId)
{
JSONObject dataJsonObj;
PullToRefreshListView list = null;
try {
dataJsonObj = new JSONObject(jsonBlob);
JSONArray jsonData = dataJsonObj.getJSONArray("steals");
ArrayList<JSONObject> data = new ArrayList<JSONObject>();
for (int i=0;i<jsonData.length();i++){
data.add(jsonData.getJSONObject(i));
}
Adapter adapter = new Adapter(contextActivity, data);
//LayoutInflater inflater = LayoutInflater.from(contextActivity);
if (tabId == 0) {
//View view = inflater.inflate(R.layout.listviewlayout, null, false);
list = (PullToRefreshListView) contextActivity.findViewById(R.id.listView);
Your code is fine .. just you need a little bit change in get view method
add a return statement.. like return rowView;
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
Log.d("GETVIEaW", "GETVIEW");
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.tab1_list_layout, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.linearItemLayout = (LinearLayout) rowView.findViewById(R.id.linearItemLayout);
viewHolder.header = (TextView) rowView.findViewById(R.id.itemHeader);
viewHolder.image = (ImageView) rowView.findViewById(R.id.itemPreImage);
viewHolder.preText = (TextView) rowView.findViewById(R.id.itemPreText);
rowView.setTag(viewHolder);
}
else{
viewHolder = (ViewHolder) rowView.getTag();
}
viewHolder.preText.setText("Type your name");
return rowView;
}
Are you sure that Log.d() is not called? You may want to change logging scope, usually default scope is info and it doesn't show debug messages. You can try to use Log.i() or change scope.
Try posting your adapter.setNotifyOnChange(true); to handler. Follow this link

Dynamically loading data to a new view

First im loading the data dynamically to a grid which is in the PMenu.java, then each item has view more button. once I pressed that I want to load the image, name and its amount in the item description view.
Im using a custom grid to load data to the grid in PMenu.java, and I have placed a button in the custom grid, so that it will navigate to viewmore.java.
I want to know once i press the button then how to load the data to viewmore.java file
PMenu.java fragment
GridView grid;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.menu_grid_main, container, false);
new PMenuAsyncTask(getActivity(), this).execute();
grid = (GridView) view.findViewById(R.id.grid);
return view;
}
#Override
public void onTaskCompleted(JSONArray responseJson) {
try {
List<String> descriptions = new ArrayList<String>();
List<String> imageUrls = new ArrayList<String>();
for (int i = 0; i < responseJson.length(); ++i) {
JSONObject object = responseJson.getJSONObject(i);
if ((object.getString("MainCategoryID")).equals("1")
&& (object.getString("SubCategoryID")).equals("1")) {
Log.i("ImageURL ", object.getString("ImageURL"));
imageUrls.add(object.getString("ImageURL"));
Log.i("Description ", object.getString("Description"));
descriptions.add(object.getString("Description"));
}
}
CustomGrid adapter = new CustomGrid(getActivity(), descriptions,
imageUrls);
grid.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
CustomGrid class
public class CustomGrid extends BaseAdapter {
private Context context;
private final List<String> descriptions;
private final List<String> imageUrls;
public CustomGrid(Context c, List<String> descriptions, List<String> imageUrls) {
this.context = c;
this.descriptions = descriptions;
this.imageUrls = imageUrls;
}
#Override
public int getCount() {
return descriptions.size();
}
#Override
public Object getItem(int position) {
return descriptions.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.fragment_pizza, parent, false);
holder.ivImage = (ImageView) convertView
.findViewById(R.id.grid_image);
holder.tvHeader = (TextView) convertView
.findViewById(R.id.grid_text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvHeader.setText(descriptions.get(position));
Picasso.with(this.context).load(imageUrls.get(position)).into(holder.ivImage);
Button backButton = (Button) convertView.findViewById(R.id.button1);
backButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent next = new Intent(context, viewmore.class);
context.startActivity(next);
next.putExtra("description", descriptions.get(position));
next.putExtra("imageUrl", imageUrls.get(position));
context.startActivity(next);
}
});
return convertView;
}
private class ViewHolder {
private TextView tvHeader;
private ImageView ivImage;
}
}
viewmore.java
public class viewmore extends Activity {
private Context context;
private final List<String> descriptions;
private final List<String> imageUrls;
public viewmore(Context c, List<String> descriptions, List<String> imageUrls) {
this.context = c;
this.descriptions = descriptions;
this.imageUrls = imageUrls;
}
private ActionBar actionBar;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_viewmore);
String description = getIntent().getStringExtra("description");
String imageUrl = getIntent().getStringExtra("imageUrl");
actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
// Associate searchable configuration with the SearchView
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
case R.id.action_cart:
return true;
case R.id.action_search:
// search action
return true;
default:
return super.onOptionsItemSelected(item);
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(
R.layout.activity_viewmore, parent, false);
holder.ivImage = (ImageView) convertView
.findViewById(R.id.grid_image);
holder.tvHeader = (TextView) convertView
.findViewById(R.id.grid_text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tvHeader.setText(descriptions.get(position));
Picasso.with(this.context).load(imageUrls.get(position)).into(holder.ivImage);
return convertView;
}
private class ViewHolder {
private TextView tvHeader;
private ImageView ivImage;
}
}
You can use intent.putExtra("key", value) methods before starting the viewmore Activity.
Then in the viewmore Activity, you can get these data from the getIntent().get*Extra("key") methods.
Like:
Intent next = new Intent(context, viewmore.class);
next.putExtra("description", descriptions.get(position));
next.putExtra("imageUrl", imageUrls.get(position));
context.startActivity(next);
Then (in viewmore Activity):
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.activity_viewmore);
String description = getIntent().getStringExtra("description");
String imageUrl = getIntent().getStringExtra("imageUrl");
// Get the TextView using its ID defined in the layout activity_viewmore.xml
TextView tv = (TextView) findViewById(R.id.my_text_view);
tv.setText(description);
ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
Picasso.with(this).load(imageUrl).into(imageView);
}

Categories

Resources