How to display full screen images when touched from ViewPager?
** I used Glide to fetch images from urls.
I was tried to intent to FullScreenActivity and sent imageUrls but i can't startActivity() via instantiateItem method from ImagePagerAdapter.java.
ImagePagerAdapter.java
public class ImagePagerAdapter extends PagerAdapter {
private Context mContext;
private String[] imageUrls;
public ImagePagerAdapter(Context mContext, String[] imageUrls) {
this.mContext = mContext;
this.imageUrls = imageUrls;
}
#Override
public int getCount() {
return imageUrls.length;
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object o) {
return view == o;
}
#NonNull
#Override
public Object instantiateItem(#NonNull final ViewGroup container, final int position) {
final ImageView imageView = new ImageView(mContext);
Glide.with(mContext)
.load(imageUrls[position])
.into(imageView);
container.addView(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Display full screen images when touched.
}
});
return imageView;
}
}
LocalExperienceDetail.java
public class LocalExperienceDetail extends AppCompatActivity {
private String[] imageUrls;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_experience_detail);
String company_name_eng = getIntent().getExtras().getString("name_eng");
String img1 = getIntent().getExtras().getString("img1");
String img2 = getIntent().getExtras().getString("img2");
String img3 = getIntent().getExtras().getString("img3");
String img4 = getIntent().getExtras().getString("img4");
String img5 = getIntent().getExtras().getString("img5");
String description_activity = getIntent().getExtras().getString("activity");
String time = getIntent().getExtras().getString("time");
String price = getIntent().getExtras().getString("price");
String tel = getIntent().getExtras().getString("tel");
String car_park = getIntent().getExtras().getString("car_park");
String address = getIntent().getExtras().getString("address");
String website = getIntent().getExtras().getString("website");
TextView tvCompanyNameEng = findViewById(R.id.txtCompanyName);
TextView tvDescActivity = findViewById(R.id.txtDescActivity);
TextView tvPrice = findViewById(R.id.txtPrice);
TextView tvTel = findViewById(R.id.txtTel);
TextView tvCarPark = findViewById(R.id.txtCarPark);
TextView tvAddress = findViewById(R.id.txtAddress);
TextView tvWebsite = findViewById(R.id.txtWebsite);
TextView tvTime = findViewById(R.id.txtTime);
ViewPager viewPager = findViewById(R.id.imgView);
tvCompanyNameEng.setText(company_name_eng);
tvDescActivity.setText(description_activity);
tvPrice.setText(price);
tvTel.setText(tel);
tvCarPark.setText(car_park);
tvAddress.setText(address);
tvWebsite.setText(website);
tvTime.setText(time);
imageUrls = new String[] {
img1,
img2,
img3,
img4,
img5
};
ImagePagerAdapter adapter = new ImagePagerAdapter(this, imageUrls);
viewPager.setAdapter(adapter);
}
}
I expect the full screen images can slide able.
Design
It is possible. Method startActivity is the method member of context class (doc)
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Display full screen images when touched.
Intent intent = new Intent(); // Your intent
mContext.startActivity(intent);
}
});
If you need to work with images, somethings like gallery, facebook has developed the Fresco library. Check it out.
Related
I want to make TextView swipeable and also scrollable as above image.
below is my code , TextView is in adapter and swipe functionality in activity.
public class MsgSwipActivity extends Base {
private static final String TAG = "MainActivity";
private SwipeDeck swipe_deck;
private ImageView imgThank;
private Toolbar toolbar;
private AdView mAdView;
private int page_no = 1;
private SwipMsgAdapter adapter;
private ArrayList<MsgListData> msgListDatas;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.msgswip);
swipe_deck = (SwipeDeck) findViewById(R.id.swipe_deck);
mAdView = (AdView) findViewById(R.id.adView);
imgThank = (ImageView) findViewById(R.id.imgThank);
imgThank.setVisibility(View.GONE);
MobileAds.initialize(MsgSwipActivity.this, getString(R.string.banner_home_footer));
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
mAdView.loadAd(adRequest);
// Start loading the ad in the background.
toolbar = (Toolbar) findViewById(R.id.toolbar);
swipe_deck.setHardwareAccelerationEnabled(true);
msgList();
msgListDatas = new ArrayList<>();
adapter = new SwipMsgAdapter(MsgSwipActivity.this, R.layout.rowmsg_item, msgListDatas);
swipe_deck.setAdapter(adapter);
swipe_deck.setEventCallback(new SwipeDeck.SwipeEventCallback() {
#Override
public void cardSwipedLeft(int position) {
Log.i("MainActivity", "card was swiped left, position in adapter: " + position);
}
#Override
public void cardSwipedRight(int position) {
Log.i("MainActivity", "card was swiped right, position in adapter: " + position);
}
#Override
public void cardsDepleted() {
page_no = page_no + 1;
msgList();
msgListDatas = new ArrayList<>();
adapter = new SwipMsgAdapter(MsgSwipActivity.this, R.layout.rowmsg_item, msgListDatas);
swipe_deck.setAdapter(adapter);
Log.i("MainActivity", "no more cards");
}
#Override
public void cardActionDown() {
Log.i(TAG, "cardActionDown");
}
#Override
public void cardActionUp() {
Log.i(TAG, "cardActionUp");
}
});
}
}
public void msgList() {
String id = getIntent().getStringExtra("ID");
String cat_id = getIntent().getStringExtra("CATID");
VLogger.infoLog(cat_id);
if (Utility.checkInternetConnection(this)) {
RetrofitClient.getInstance().getRestOkClient().
msgSticky("ListingShayariSingle",
cat_id,
((VApp) getApplicationContext()).getCheck()
, id, String.valueOf(page_no), callback);
} else {
Toast.makeText(MsgSwipActivity.this, "No Intetnet please try again", Toast.LENGTH_SHORT).show();
}
}
private final retrofit.Callback callback = new retrofit.Callback() {
#Override
public void success(Object object, Response response) {
MsgList msgList = (MsgList) object;
if (msgList.getData() != null) {
for (int i = 0; i < msgList.getData().size(); i++) {
MsgListData item = new MsgListData();
item.setId(msgList.getData().get(i).getId());
item.setReg_date(msgList.getData().get(i).getReg_date());
item.setStatus(msgList.getData().get(i).getStatus());
item.setDetails(msgList.getData().get(i).getDetails());
item.setCategory(msgList.getData().get(i).getCategory());
item.setLanguage(msgList.getData().get(i).getLanguage());
item.setColor_code(msgList.getData().get(i).getColor_code());
getSupportActionBar().setTitle(msgList.getData().get(i).getC_name().toString());
msgListDatas.add(item);
}
adapter.setGridData(msgListDatas);
} else {
imgThank.setVisibility(View.VISIBLE);
}
}
#Override
public void failure(RetrofitError error) {
Toast.makeText(MsgSwipActivity.this, "Server Error", Toast.LENGTH_SHORT).show();
}
};
}
and here is my adapter
public class SwipMsgAdapter extends ArrayAdapter<MsgListData>{
private ArrayList<MsgListData> rowDatas;
private Context context;
private int layoutResourceId;
public EditText edtSave;
public String image_Id;
private boolean checked;
Uri bmpUri;
private ImageView imgFav, imgCopy, imgFb, imgShare, imgHike;
private ImageView imgWhatsapp;
private TextView imgMain;
private View positiveAction;
CallbackManager callbackManager;
ShareDialog shareDialog;
public SwipMsgAdapter(Context context, int layoutResourceId, ArrayList<MsgListData> rowDatas) {
super(context, layoutResourceId, rowDatas);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.rowDatas = rowDatas;
}
public void setGridData(ArrayList<MsgListData> rowDatas) {
this.rowDatas = rowDatas;
notifyDataSetChanged();
}
#Override
public int getCount() {
return rowDatas.size();
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
FacebookSdk.sdkInitialize(context.getApplicationContext());
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// normally use a viewholder
v = inflater.inflate(R.layout.rowmsg_item, parent, false);
}
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog((Activity) context);
imgMain = (TextView) v.findViewById(R.id.imgMain);
imgFav = (ImageView) v.findViewById(R.id.imgFav);
imgCopy = (ImageView) v.findViewById(R.id.imgCopy);
imgHike = (ImageView) v.findViewById(R.id.imgHike);
imgWhatsapp = (ImageView) v.findViewById(R.id.imgWhatsapp);
imgFb = (ImageView) v.findViewById(R.id.imgFb);
imgShare = (ImageView) v.findViewById(R.id.imgShare);
CardView card_view = (CardView) v.findViewById(R.id.card_view);
int color = Color.parseColor(rowDatas.get(position).getColor_code());
card_view.setCardBackgroundColor(color);
image_Id = rowDatas.get(position).getId();
imgMain.setText(rowDatas.get(position).getDetails());
VLogger.infoLog("IMAGE" + String.valueOf(bmpUri));
RetrofitClient.getInstance().getRestOkClient().
checkMsgFavorite("AvailableFavoritText", VPreferences.getPreferanceDeviceID(context)
, rowDatas.get(position).getId(), checkCallback);
};
how can i implement both functionality scroll and swipe?
Scrollable TextView: Put the TextView as the child of a ScrollView.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</ScrollView>
Remember that a ScrollView can only hold ONE object.
For Gestures, look at Detecting Common Gestures
EDIT:
You can also use this line of code in the XML and see if it works (with the textview):
android:scrollbars="vertical"
Put your textview inside scrollview in xml. Then make it "swipeable" programmatically. Stackoverflow is telling me that my answer does not meet their quality standards.
hello i have this Json Data a link
and i parsing it like that
when i click into the image i want to parsing the JsonArray for the image to piccaso in recycler view like this ,
but i get all image like this picture
how i can solve this problem and get just the images for the item which i clicked ???
this is my module :
public class AppShowModule
{
private List<String> Allimage = new ArrayList<String>();
public List<String> getAllimage() {
return Allimage;}
public void setAllimage(List<String> allimage) {
Allimage = allimage;}
this is my Fragment
public class ImageListFragment extends Fragment {
List<AppShowModule> appShowModules;
List<AppShowModule> imagesModule;
RecyclerView AppRecyclerView;
RecyclerView.Adapter imageRecyclerViewadapter;
List<String> imageUrls;
String feedKey = "feed";
String entryKey = "entry";
String imageKey = "im:image";
String labelKey = "label";
String jsonUrl = "https://itunes.apple.com/jo/rss/topfreeapplications/limit=50/json";
RequestQueue requestQueue;
private RecyclerView.LayoutManager mLayoutManager;
public ImageListFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_image_list, container, false);
}
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppRecyclerView = (RecyclerView) getView().findViewById(R.id.imageRecyclerView);
imagesModule = new ArrayList<>();
appShowModules = new ArrayList<>();
imageUrls = new ArrayList<>();
JsonAppShowData();
}
public void JsonAppShowData() {
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( jsonUrl, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONObject(feedKey).getJSONArray( entryKey );
AppShowModule appShowModule = new AppShowModule();
for (int i = 0; i < jsonArray.length(); i++) {
JSONArray imageArray = response.getJSONObject(feedKey).getJSONArray(entryKey).getJSONObject(i).getJSONArray(imageKey);
for (int j = 0; j < imageArray.length(); j++) {
String image = imageArray.getJSONObject(j).getString(labelKey).toString();
imageUrls.add(image);
appShowModule.setAllimage(imageUrls);
appShowModules.add(appShowModule);}}
imageRecyclerViewadapter = new ImageListAdapter(appShowModules,getContext(),imageUrls);
AppRecyclerView.setAdapter(imageRecyclerViewadapter);
} catch (JSONException e) {
e.printStackTrace();
}}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e( "LOG", error.toString() );
}
} );
requestQueue = Volley.newRequestQueue( getContext() );
requestQueue.add(jsonObjectRequest);
mLayoutManager = new GridLayoutManager( getContext().getApplicationContext(),3);
AppRecyclerView.setLayoutManager(mLayoutManager); }}
and this is the Recycler adapter
public class ImageListAdapter extends RecyclerView.Adapter<ImageListAdapter.ViewHolder> {
List<AppShowModule> appShowModules;
List<String> imageUrl;
Context context;
public ImageListAdapter(List<AppShowModule> appShowModules, Context context ,List<String>imageUrls
){
super();
this.imageUrl =imageUrls;
this.appShowModules = appShowModules;
this.context = context;}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.imagelayout, parent,false );
ViewHolder viewHolder = new ViewHolder( v );
return viewHolder;}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
Picasso.with(context).load(imageUrl.get(position)).into(holder.appImage);
}
public int getItemCount() {
return imageUrl.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ImageView appImage;
public ViewHolder(View itemView) {
super(itemView);
appImage = (ImageView) itemView.findViewById( R.id.appImage);
}}}
and this is the activity that have the image view where click
public class ListViewDetailsFragment extends Fragment {
ImageView AppImage;
TextView AppName,AppArtist,AppContentType,AppRights,AppCategory,AppRealseDate,AppSammary;
ImageButton AppLink;
Context context;
public ListViewDetailsFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_list_view_details, container, false);}
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
AppImage = (ImageView) getView().findViewById(R.id.imageView);
AppName = (TextView) getView().findViewById(R.id.textname);
AppArtist = (TextView) getView().findViewById(R.id.textartest);
AppContentType = (TextView) getView().findViewById(R.id.textcontent);
AppRights = (TextView) getView().findViewById(R.id.textrights);
AppCategory = (TextView) getView().findViewById(R.id.textCategory);
AppRealseDate = (TextView) getView().findViewById(R.id.textRelease);
AppSammary = (TextView) getView().findViewById(R.id.textSummary);
AppLink = (ImageButton) getView().findViewById(R.id.imageButton);
String name = getActivity().getIntent().getExtras().getString("App_name");
final String image = getActivity().getIntent().getExtras().getString("App_image");
String artist = getActivity().getIntent().getExtras().getString("App_artist");
String contentType = getActivity().getIntent().getExtras().getString("App_ContentType");
String rights = getActivity().getIntent().getExtras().getString("App_Rights");
String category = getActivity().getIntent().getExtras().getString("App_Category");
String realse = getActivity().getIntent().getExtras().getString("App_ReleaseDate");
final String link = getActivity().getIntent().getExtras().getString("App_link");
String sammary = getActivity().getIntent().getExtras().getString("App_summary");
AppName.setText(name);
AppArtist.setText(artist);
AppContentType.setText(contentType);
AppRights.setText(rights);
AppCategory.setText(category);
AppRealseDate.setText(realse);
AppSammary.setText(sammary);
Picasso.with(context).load(image).into(AppImage);
AppLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity().getBaseContext(),
WebView.class);
intent.putExtra("App_link", link);
getActivity().startActivity(intent);}});
AppImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String id = (String) view.getTag();
Intent intent = new Intent(getActivity().getBaseContext(), ImageList.class);
intent.putExtra("id", id);
getActivity().startActivity(intent);
}});}}
The json data has links to three different sized images, it looks to me like you are requesting that all three images are fetched. If you don't want all three, just select the size you want (index 0, 1 or 2) and pull that image only.
JSONArray imageArray = response.getJSONObject(feedKey).getJSONArray(entryKey).getJSONObject(i).getJSONArray(imageKey);
for (int j = 0; j < imageArray.length(); j++) {
String image = imageArray.getJSONObject(j).getString(labelKey).toString();
imageUrls.add(image);
...
}
Sample Data:
"im:image":[
{
"label":"http://is1.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/53x53bb-85.png",
"attributes":{
"height":"53"
}
},
{
"label":"http://is5.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/75x75bb-85.png",
"attributes":{
"height":"75"
}
},
{
"label":"http://is3.mzstatic.com/image/thumb/Purple20/v4/87/35/82/87358231-ce91-3d14-b306-95888c23db3c/mzl.gdgtivnk.png/100x100bb-85.png",
"attributes":{
"height":"100"
}
}
Update 9/13/2016
Based on what I think you are after, I still think your problem is in your nested for loop in the jsonAppShowData() method. Though you do appear to pass some sort of ID extra in from the previous activity, I don't see you filtering on that item ID anywhere in the for loop. You need to restrict the outer for loop to only the item you wish to show.
For the image scaling issue, it may either be how your layout is setup or you can try some of the Picasso resize calls.
In my app,I store the image in SQLite and read read it from there. I can display it,in a recyclerview using picasso. But when I launch a new activity,by clicking a row,the image doesn't appear.
Here is my code.
From this adapter I get the image and the other data from the database.
public class MySQLAdapter extends RecyclerView.Adapter<MySQLAdapter.RowHolderClass> {
private List<SQLiteModel> myList;
private Context mContext;
private int focused;
public MySQLAdapter(Activity activity,ArrayList<SQLiteModel> ss) {
this.myList = ss;
this.mContext=activity;
}
#Override
public MySQLAdapter.RowHolderClass onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sqlite_adapter, null);
final RowHolderClass holder = new RowHolderClass(v);
return holder;
}
#Override
public void onBindViewHolder(RowHolderClass holder, int position) {
final SQLiteModel listItems = myList.get(position);
holder.itemView.setSelected(focused==position);
Picasso.with(holder.imageView.getContext())
.load(myList.get(position).getSqliteImage()).into(holder.imageView);
holder.fName.setText(myList.get(position).getSqliteFirstName());
holder.lName.setText(myList.get(position).getSqliteSecondName());
holder.jobRole.setText(myList.get(position).getSqliteRole());
//holder.imageView.setImageResource(Integer.parseInt(myList.get(position).getSqliteImage()));
holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String first_name = listItems.getSqliteFirstName();
String last_name = listItems.getSqliteSecondName();
String job_role = listItems.getSqliteRole();
String image_url = listItems.getSqliteImage();
String id= String.valueOf(listItems.getSqliteId());
//Log.v("id",id);
Intent i = new Intent(mContext, NoInternetDetailedActivity.class);
i.putExtra("firstName",first_name);
i.putExtra("lastName",last_name);
i.putExtra("jobRole",job_role);
i.putExtra("imageUrl",image_url);
i.putExtra("memberId",id);
mContext.startActivity(i);
}
});
}
#Override
public int getItemCount() {
return myList.size();
}
//ViewHolder pattern used to read the data of the row fast.
class RowHolderClass extends RecyclerView.ViewHolder {
protected ImageView imageView;
protected TextView fName, lName, jobRole;
protected RelativeLayout relativeLayout;
public RowHolderClass(View itemView) {
super(itemView);
this.relativeLayout = (RelativeLayout) itemView.findViewById(R.id.recLayout);
this.imageView = (ImageView) itemView.findViewById(R.id.imageView);
this.fName = (TextView) itemView.findViewById(R.id.firstName);
this.lName = (TextView) itemView.findViewById(R.id.lastName);
this.jobRole = (TextView) itemView.findViewById(R.id.roleView);
}
}
}
Then I pass the data in a new activity.
public class NoInternetDetailedActivity extends AppCompatActivity {
ImageView imageView;
TextView textView0,textView1,textView2,textView3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_no_internet_detailed);
Intent i = getIntent();
String memberId = i.getExtras().getString("memberId");
String firstName = i.getExtras().getString("firstName");
String lastName = i.getExtras().getString("lastName");
String jobRole = i.getExtras().getString("jobRole");
String image = i.getExtras().getString("imageUrl");
//imageView = (ImageView)findViewById(R.id.newImageView);
textView0 = (TextView)findViewById(R.id.textView0);
textView1 = (TextView)findViewById(R.id.textView1);
textView2 = (TextView)findViewById(R.id.textView2);
textView3 = (TextView)findViewById(R.id.textView3);
textView0.setText("Member id: "+ memberId);
textView1.setText(firstName);
textView2.setText(lastName);
textView3.setText(jobRole);
//This line gives me the exception!
Picasso.with(this).load(image).into(imageView);
}
}
The exception I get is:
Caused by: java.lang.IllegalArgumentException: Target must not be null.
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:618)
at com.squareup.picasso.RequestCreator.into(RequestCreator.java:601)
Any ideas?
Thanks,
Theo.
/*Use this aproach*/
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
/* wifi is not enabled */
if (!wifi.isWifiEnabled()){
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
Intent intent = new Intent(this, NewActivity.class);
intent.putExtra("BitmapImage", bitmap);
}
/* Receive image on second activity */
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
In my app,I sucessfully retrieve from a webserver a list of images. They are read as urls ie
http://mw2.google.com/mw-panoramio/photos/medium/131093147.jpg
and so on.
I store the images in the SQLite as string urls. But now I want to display them in a recyclerview.
This is my adapter.
public class MySQLAdapter extends RecyclerView.Adapter<MySQLAdapter.RowHolderClass> {
private List<SQLiteModel> myList;
private Context mContext;
private int focused;
public MySQLAdapter(Activity activity,ArrayList<SQLiteModel> ss) {
this.myList = ss;
this.mContext=activity;
}
#Override
public MySQLAdapter.RowHolderClass onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_row, null);
final RowHolderClass holder = new RowHolderClass(v);
return holder;
}
#Override
public void onBindViewHolder(RowHolderClass holder, int position) {
final SQLiteModel listItems = myList.get(position);
holder.itemView.setSelected(focused==position);
holder.getLayoutPosition();
holder.fName.setText(myList.get(position).getSqliteFirstName());
holder.lName.setText(myList.get(position).getSqliteSecondName());
holder.jobRole.setText(myList.get(position).getSqliteRole());
//holder.imageView.setImageResource(Integer.parseInt(myList.get(position).getSqliteImage()));
holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String first_name = listItems.getSqliteFirstName();
String last_name = listItems.getSqliteSecondName();
String job_role = listItems.getSqliteRole();
//String image_url = listItems.get();
//String id= String.valueOf(listItems.getSqliteId());
//Log.v("id",id);
Intent i = new Intent(mContext, NoInternetDetailedActivity.class);
i.putExtra("firstName",first_name);
i.putExtra("lastName",last_name);
i.putExtra("jobRole",job_role);
//i.putExtra("imageUrl",image_url);
//i.putExtra("memberId",id);
mContext.startActivity(i);
}
});
}
#Override
public int getItemCount() {
return myList.size();
}
//ViewHolder pattern used to read the data of the row fast.
class RowHolderClass extends RecyclerView.ViewHolder {
protected NetworkImageView imageView;
protected TextView fName, lName, jobRole;
protected RelativeLayout relativeLayout;
public RowHolderClass(View itemView) {
super(itemView);
this.relativeLayout = (RelativeLayout) itemView.findViewById(R.id.recLayout);
this.imageView = (NetworkImageView) itemView.findViewById(R.id.imageView);
this.fName = (TextView) itemView.findViewById(R.id.firstName);
this.lName = (TextView) itemView.findViewById(R.id.lastName);
this.jobRole = (TextView) itemView.findViewById(R.id.roleView);
}
}
}
Ι display the rest of the data inside the onBindViewHolder as
holder.fName.setText(myList.get(position).getSqliteFirstName());
holder.lName.setText(myList.get(position).getSqliteSecondName());
holder.jobRole.setText(myList.get(position).getSqliteRole());
I think I need to convert the URL String into a byte array inside that method. I am not sure. Any ideas?
And something else. When I click on recyclerview's row I get the following exception.
java.lang.NullPointerException: Attempt to invoke virtual method
'java.lang.String android.content.Context.getPackageName()' on a null object
reference
at android.content.ComponentName.<init>(ComponentName.java:77)
This is how my recyclerview looks like without the image.
public void fetchDataFromDB() {
dba = new DatabaseHandler(getApplicationContext());
ArrayList<SQLiteModel> membersDB = dba.getMembersDetails();
for(int i=0; i<membersDB.size();i++){
int id = membersDB.get(i).getSqliteId();
String fname = membersDB.get(i).getSqliteFirstName();
String lname = membersDB.get(i).getSqliteSecondName();
String role = membersDB.get(i).getSqliteRole();
String image = membersDB.get(i).getSqliteImage();
//String desc = moviesFromDB.get(i).getContent();
SQLiteModel f = new SQLiteModel();
f.setSqliteId(id);
f.setSqliteFirstName(fname);
f.setSqliteSecondName(lname);
f.setSqliteRole(role);
f.setSqliteImage(image);
myarr.add(f);
}
dba.close();
}
}
Use
Picasso
This is very simple library which allows you to download and cache you images.
So in you case you should write something like:
Picasso.with(mContext)
.load(myList.get(position).getSqliteImage())
.into(holder.imageView);
You have there NetworkImageView, that is currently less and less used. I would suggest you to change this to standard ImageView + using Picasso library, then you can load image by:
Picasso.with(holder.imageView.getContext()).load(myList.get(position).getUrl()).into(holder.imageView);
Thanks to Mateusz Pryczkowski
The answer for the images is:
Picasso.with(holder.imageView.getContext())
.load(myList.get(position).getSqliteImage()).into(holder.imageView);
I have successfully passed my title and description using the code below, but when i try to pass my header image, nothing happens. Where is my error?
MyPageHolder.java
public abstract class MyPageHolder extends RecyclerView.ViewHolder{
protected final Activity activity;
protected MyPageAdapter adapter;
public TextView txtTitle, txtDescription;
public ImageView imgImage;
public View view;
public MyPageHolder(View v, Activity activity, MyPageAdapter adapter) {
super(v);
this.activity = activity;
this.adapter = adapter;
imgImage = (ImageView) v.findViewById(R.id.cardview_image);
txtTitle = (TextView) v.findViewById(R.id.cardview_title);
txtDescription = (TextView) v.findViewById(R.id.cardview_description);
view = (CardView) v.findViewById(R.id.card_view);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
/*/ this is where the magic happens when clicked /*/
}
});
}
public void bind(MenuPageItems dataModel, Activity activity, final int position) {
final MenuPageItems m = (MenuPageItems)dataModel;
imgImage.setImageResource(m.image);
txtTitle.setText(m.title);
txtDescription.setText(m.description);
view.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v){
Intent cvIntent = new Intent(view.getContext(), EndpageActivity.class);
cvIntent.putExtra("endpageHeader", m.image);
// text to pass to endpage activity
cvIntent.putExtra("endpageTitle", m.title);
cvIntent.putExtra("endpageTheContent", m.description);
view.getContext().startActivity(cvIntent);
}
});
}
}
EndpageActivity.java
public class EndpageActivity extends AppCompatActivity {
TextView t1;
ImageView iv1;
private void loadBackdrop() {
String uri = "#drawable/p400x200";
// where backdropX.jpg (without the extension) is the file
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
final ImageView imageView = (ImageView) findViewById(R.id.endpage_header_image);
Drawable res = getResources().getDrawable(imageResource);
imageView.setImageDrawable(res);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.endpage_layout);
Intent intent = getIntent();
String sTitle = intent.getStringExtra("endpageTitle");
String sTheContent = intent.getStringExtra("endpageTheContent");
CollapsingToolbarLayout collapsingToolbar =
(CollapsingToolbarLayout) findViewById(R.id.endpage_header);
collapsingToolbar.setTitle(sTitle);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// this adds the back button arrow to the header
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
iv1 = (ImageView) findViewById(R.id.endpage_header_image);
iv1.setImageDrawable(getResources().getDrawable(getIntent().getIntExtra("endpageHeader", 0)));
t1 = (TextView)findViewById(R.id.endpage_the_content);
t1.setText(sTheContent);
loadBackdrop();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.sample_actions, menu);
return true;
}
}
the app runs but only my text changes, the imageview is still showing my placeholder image.
Please try this
iv1.setImageResource(getIntent().getExtras().getInt("endpageHeader"));
If it is also not working,print your
getIntent().getExtras().getInt("endpageHeader")
value in log and check it is of the form `R.drawable.your_image`