update image in page of viewpager instantly
I am trying to set an image of the button dynamically when the button is pressed. i am not able to do it as the page in view pager is not getting updated automatically. here is the code below. In the instantiateitem method i am trying to set an image based on click. It works for first time then i have to go back again and come back to get the updated view. I need to update it instantly. Please Help out
public class ShowDetailsActivity extends AppCompatActivity
private List<Quote> modelList;
private ViewPagerAdapter viewPagerAdapter;
private ViewPager viewPager;
private MyDataBase db;
private Cursor quotes;
ImageButton imgshare;
TextView head;
private static final String TAG = "ShowDetailsActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showdetails);
head = findViewById(R.id.head);
viewPager = findViewById(R.id.viewpager);
modelList = new ArrayList<>();
String category="";
ArrayList<String> ar = new ArrayList<String>();
ArrayList<String> ar_id = new ArrayList<String>();
ArrayList<String> ar_category = new ArrayList<String>();
ArrayList<String> ar_bookmark = new ArrayList<String>();
db = new MyDataBase(this);
if(getIntent().getExtras()!=null)
category =getIntent().getExtras().getString("category");
switch (category)
case "romance":
quotes = db.getQuotes("romance");
head.setText("Romantic");
break;
case "breakup":
quotes = db.getQuotes("breakup");
head.setText("Break Up");
break;
case "favorite":
quotes = db.allBookmarks();
head.setText("Bookmarks");
break;
if(quotes!=null && quotes.moveToFirst())
do
ar_id.add(quotes.getString(0));
ar.add(quotes.getString(1));
ar_bookmark.add(quotes.getString(2));
ar_category.add(quotes.getString(3));
while(quotes.moveToNext());
for (int i = 0 ; i < ar.size() ; i++)
Quote quote = new Quote();
quote.setQuote(ar.get(i));
quote.setCategory(ar_category.get(i));
quote.setId(Integer.parseInt(ar_id.get(i)));
quote.setBookmark(Integer.parseInt(ar_bookmark.get(i)));
modelList.add(quote);
viewPagerAdapter = new ViewPagerAdapter(modelList,this);
viewPagerAdapter.notifyDataSetChanged();
viewPager.setAdapter(viewPagerAdapter);
if(getIntent().getIntExtra("id",0) != -1)
Bundle extras = getIntent().getExtras();
int pos = getIntent().getIntExtra("id",0);
Log.d(TAG, "pos"+pos);
viewPager.setCurrentItem(pos,true);
public class ViewPagerAdapter extends PagerAdapter
private List<Quote> quotesList;
private Context context;
private static final String TAG = "ViewPagerAdapter";
ImageButton imgshare,imgcopy,imgencshare,imgbookmark;
private MyDataBase db;
public ViewPagerAdapter(List<Quote> quotesList, Context context)
this.quotesList = quotesList;
this.context = context;
@Override
public int getCount()
return quotesList.size();
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o)
return view == (RelativeLayout) o;
@Override
public Object instantiateItem(ViewGroup container, final int position)
Log.d(TAG, "saiinstantiateItem: ");
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.viewpager_contents, container, false);
//container is a viewgroup.
TextView quotes = view.findViewById(R.id.quotes);
quotes.setText(quotesList.get(position).getQuote());
final String send = quotesList.get(position).getQuote();
db = new MyDataBase(context);
imgshare = (ImageButton) view.findViewById(R.id.btn_share);
imgcopy= (ImageButton) view.findViewById(R.id.btn_copy_quote);
imgencshare= (ImageButton) view.findViewById(R.id.btn_encrypt_and_share);
imgbookmark = (ImageButton) view.findViewById(R.id.btn_favorite);
// quotesList.get(position)
Log.d(TAG, "instantiateItemQuote: "+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
Log.d(TAG, "instantiateItem: "+quotesList.get(position).getBookmark());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
imgbookmark.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
// Log.d(TAG, "clicky"+quotesList.get(position).getId());
// Log.d(TAG, "clickycat"+quotesList.get(position).getCategory());
Log.d(TAG, "clickycat"+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
db.removeBookmark(quotesList.get(position).getCategory(),quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_black_24dp);
Toast.makeText(context, "Bookmark removed",
Toast.LENGTH_SHORT).show();
else
db.addBookmark(quotesList.get(position).getCategory(), quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
Toast.makeText(context, "Bookmarked",
Toast.LENGTH_SHORT).show();
);
imgencshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String password = "password";
try
String encryptedMsg = AESCrypt.encrypt(password, send);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, encryptedMsg);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
catch (GeneralSecurityException e)
//handle error
);
imgcopy.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String copytext;
copytext = send;
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(null, send);
if (clipboard == null) return;
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Text Copied",
Toast.LENGTH_SHORT).show();
);
imgshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, send);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
);
container.addView(view);
return view;
@Override
public void destroyItem(ViewGroup container, int position, Object object)
container.removeView((View) object);
public int getItemPosition(Object object)
return POSITION_NONE;
java android
add a comment |
I am trying to set an image of the button dynamically when the button is pressed. i am not able to do it as the page in view pager is not getting updated automatically. here is the code below. In the instantiateitem method i am trying to set an image based on click. It works for first time then i have to go back again and come back to get the updated view. I need to update it instantly. Please Help out
public class ShowDetailsActivity extends AppCompatActivity
private List<Quote> modelList;
private ViewPagerAdapter viewPagerAdapter;
private ViewPager viewPager;
private MyDataBase db;
private Cursor quotes;
ImageButton imgshare;
TextView head;
private static final String TAG = "ShowDetailsActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showdetails);
head = findViewById(R.id.head);
viewPager = findViewById(R.id.viewpager);
modelList = new ArrayList<>();
String category="";
ArrayList<String> ar = new ArrayList<String>();
ArrayList<String> ar_id = new ArrayList<String>();
ArrayList<String> ar_category = new ArrayList<String>();
ArrayList<String> ar_bookmark = new ArrayList<String>();
db = new MyDataBase(this);
if(getIntent().getExtras()!=null)
category =getIntent().getExtras().getString("category");
switch (category)
case "romance":
quotes = db.getQuotes("romance");
head.setText("Romantic");
break;
case "breakup":
quotes = db.getQuotes("breakup");
head.setText("Break Up");
break;
case "favorite":
quotes = db.allBookmarks();
head.setText("Bookmarks");
break;
if(quotes!=null && quotes.moveToFirst())
do
ar_id.add(quotes.getString(0));
ar.add(quotes.getString(1));
ar_bookmark.add(quotes.getString(2));
ar_category.add(quotes.getString(3));
while(quotes.moveToNext());
for (int i = 0 ; i < ar.size() ; i++)
Quote quote = new Quote();
quote.setQuote(ar.get(i));
quote.setCategory(ar_category.get(i));
quote.setId(Integer.parseInt(ar_id.get(i)));
quote.setBookmark(Integer.parseInt(ar_bookmark.get(i)));
modelList.add(quote);
viewPagerAdapter = new ViewPagerAdapter(modelList,this);
viewPagerAdapter.notifyDataSetChanged();
viewPager.setAdapter(viewPagerAdapter);
if(getIntent().getIntExtra("id",0) != -1)
Bundle extras = getIntent().getExtras();
int pos = getIntent().getIntExtra("id",0);
Log.d(TAG, "pos"+pos);
viewPager.setCurrentItem(pos,true);
public class ViewPagerAdapter extends PagerAdapter
private List<Quote> quotesList;
private Context context;
private static final String TAG = "ViewPagerAdapter";
ImageButton imgshare,imgcopy,imgencshare,imgbookmark;
private MyDataBase db;
public ViewPagerAdapter(List<Quote> quotesList, Context context)
this.quotesList = quotesList;
this.context = context;
@Override
public int getCount()
return quotesList.size();
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o)
return view == (RelativeLayout) o;
@Override
public Object instantiateItem(ViewGroup container, final int position)
Log.d(TAG, "saiinstantiateItem: ");
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.viewpager_contents, container, false);
//container is a viewgroup.
TextView quotes = view.findViewById(R.id.quotes);
quotes.setText(quotesList.get(position).getQuote());
final String send = quotesList.get(position).getQuote();
db = new MyDataBase(context);
imgshare = (ImageButton) view.findViewById(R.id.btn_share);
imgcopy= (ImageButton) view.findViewById(R.id.btn_copy_quote);
imgencshare= (ImageButton) view.findViewById(R.id.btn_encrypt_and_share);
imgbookmark = (ImageButton) view.findViewById(R.id.btn_favorite);
// quotesList.get(position)
Log.d(TAG, "instantiateItemQuote: "+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
Log.d(TAG, "instantiateItem: "+quotesList.get(position).getBookmark());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
imgbookmark.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
// Log.d(TAG, "clicky"+quotesList.get(position).getId());
// Log.d(TAG, "clickycat"+quotesList.get(position).getCategory());
Log.d(TAG, "clickycat"+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
db.removeBookmark(quotesList.get(position).getCategory(),quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_black_24dp);
Toast.makeText(context, "Bookmark removed",
Toast.LENGTH_SHORT).show();
else
db.addBookmark(quotesList.get(position).getCategory(), quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
Toast.makeText(context, "Bookmarked",
Toast.LENGTH_SHORT).show();
);
imgencshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String password = "password";
try
String encryptedMsg = AESCrypt.encrypt(password, send);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, encryptedMsg);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
catch (GeneralSecurityException e)
//handle error
);
imgcopy.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String copytext;
copytext = send;
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(null, send);
if (clipboard == null) return;
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Text Copied",
Toast.LENGTH_SHORT).show();
);
imgshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, send);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
);
container.addView(view);
return view;
@Override
public void destroyItem(ViewGroup container, int position, Object object)
container.removeView((View) object);
public int getItemPosition(Object object)
return POSITION_NONE;
java android
add a comment |
I am trying to set an image of the button dynamically when the button is pressed. i am not able to do it as the page in view pager is not getting updated automatically. here is the code below. In the instantiateitem method i am trying to set an image based on click. It works for first time then i have to go back again and come back to get the updated view. I need to update it instantly. Please Help out
public class ShowDetailsActivity extends AppCompatActivity
private List<Quote> modelList;
private ViewPagerAdapter viewPagerAdapter;
private ViewPager viewPager;
private MyDataBase db;
private Cursor quotes;
ImageButton imgshare;
TextView head;
private static final String TAG = "ShowDetailsActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showdetails);
head = findViewById(R.id.head);
viewPager = findViewById(R.id.viewpager);
modelList = new ArrayList<>();
String category="";
ArrayList<String> ar = new ArrayList<String>();
ArrayList<String> ar_id = new ArrayList<String>();
ArrayList<String> ar_category = new ArrayList<String>();
ArrayList<String> ar_bookmark = new ArrayList<String>();
db = new MyDataBase(this);
if(getIntent().getExtras()!=null)
category =getIntent().getExtras().getString("category");
switch (category)
case "romance":
quotes = db.getQuotes("romance");
head.setText("Romantic");
break;
case "breakup":
quotes = db.getQuotes("breakup");
head.setText("Break Up");
break;
case "favorite":
quotes = db.allBookmarks();
head.setText("Bookmarks");
break;
if(quotes!=null && quotes.moveToFirst())
do
ar_id.add(quotes.getString(0));
ar.add(quotes.getString(1));
ar_bookmark.add(quotes.getString(2));
ar_category.add(quotes.getString(3));
while(quotes.moveToNext());
for (int i = 0 ; i < ar.size() ; i++)
Quote quote = new Quote();
quote.setQuote(ar.get(i));
quote.setCategory(ar_category.get(i));
quote.setId(Integer.parseInt(ar_id.get(i)));
quote.setBookmark(Integer.parseInt(ar_bookmark.get(i)));
modelList.add(quote);
viewPagerAdapter = new ViewPagerAdapter(modelList,this);
viewPagerAdapter.notifyDataSetChanged();
viewPager.setAdapter(viewPagerAdapter);
if(getIntent().getIntExtra("id",0) != -1)
Bundle extras = getIntent().getExtras();
int pos = getIntent().getIntExtra("id",0);
Log.d(TAG, "pos"+pos);
viewPager.setCurrentItem(pos,true);
public class ViewPagerAdapter extends PagerAdapter
private List<Quote> quotesList;
private Context context;
private static final String TAG = "ViewPagerAdapter";
ImageButton imgshare,imgcopy,imgencshare,imgbookmark;
private MyDataBase db;
public ViewPagerAdapter(List<Quote> quotesList, Context context)
this.quotesList = quotesList;
this.context = context;
@Override
public int getCount()
return quotesList.size();
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o)
return view == (RelativeLayout) o;
@Override
public Object instantiateItem(ViewGroup container, final int position)
Log.d(TAG, "saiinstantiateItem: ");
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.viewpager_contents, container, false);
//container is a viewgroup.
TextView quotes = view.findViewById(R.id.quotes);
quotes.setText(quotesList.get(position).getQuote());
final String send = quotesList.get(position).getQuote();
db = new MyDataBase(context);
imgshare = (ImageButton) view.findViewById(R.id.btn_share);
imgcopy= (ImageButton) view.findViewById(R.id.btn_copy_quote);
imgencshare= (ImageButton) view.findViewById(R.id.btn_encrypt_and_share);
imgbookmark = (ImageButton) view.findViewById(R.id.btn_favorite);
// quotesList.get(position)
Log.d(TAG, "instantiateItemQuote: "+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
Log.d(TAG, "instantiateItem: "+quotesList.get(position).getBookmark());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
imgbookmark.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
// Log.d(TAG, "clicky"+quotesList.get(position).getId());
// Log.d(TAG, "clickycat"+quotesList.get(position).getCategory());
Log.d(TAG, "clickycat"+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
db.removeBookmark(quotesList.get(position).getCategory(),quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_black_24dp);
Toast.makeText(context, "Bookmark removed",
Toast.LENGTH_SHORT).show();
else
db.addBookmark(quotesList.get(position).getCategory(), quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
Toast.makeText(context, "Bookmarked",
Toast.LENGTH_SHORT).show();
);
imgencshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String password = "password";
try
String encryptedMsg = AESCrypt.encrypt(password, send);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, encryptedMsg);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
catch (GeneralSecurityException e)
//handle error
);
imgcopy.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String copytext;
copytext = send;
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(null, send);
if (clipboard == null) return;
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Text Copied",
Toast.LENGTH_SHORT).show();
);
imgshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, send);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
);
container.addView(view);
return view;
@Override
public void destroyItem(ViewGroup container, int position, Object object)
container.removeView((View) object);
public int getItemPosition(Object object)
return POSITION_NONE;
java android
I am trying to set an image of the button dynamically when the button is pressed. i am not able to do it as the page in view pager is not getting updated automatically. here is the code below. In the instantiateitem method i am trying to set an image based on click. It works for first time then i have to go back again and come back to get the updated view. I need to update it instantly. Please Help out
public class ShowDetailsActivity extends AppCompatActivity
private List<Quote> modelList;
private ViewPagerAdapter viewPagerAdapter;
private ViewPager viewPager;
private MyDataBase db;
private Cursor quotes;
ImageButton imgshare;
TextView head;
private static final String TAG = "ShowDetailsActivity";
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_showdetails);
head = findViewById(R.id.head);
viewPager = findViewById(R.id.viewpager);
modelList = new ArrayList<>();
String category="";
ArrayList<String> ar = new ArrayList<String>();
ArrayList<String> ar_id = new ArrayList<String>();
ArrayList<String> ar_category = new ArrayList<String>();
ArrayList<String> ar_bookmark = new ArrayList<String>();
db = new MyDataBase(this);
if(getIntent().getExtras()!=null)
category =getIntent().getExtras().getString("category");
switch (category)
case "romance":
quotes = db.getQuotes("romance");
head.setText("Romantic");
break;
case "breakup":
quotes = db.getQuotes("breakup");
head.setText("Break Up");
break;
case "favorite":
quotes = db.allBookmarks();
head.setText("Bookmarks");
break;
if(quotes!=null && quotes.moveToFirst())
do
ar_id.add(quotes.getString(0));
ar.add(quotes.getString(1));
ar_bookmark.add(quotes.getString(2));
ar_category.add(quotes.getString(3));
while(quotes.moveToNext());
for (int i = 0 ; i < ar.size() ; i++)
Quote quote = new Quote();
quote.setQuote(ar.get(i));
quote.setCategory(ar_category.get(i));
quote.setId(Integer.parseInt(ar_id.get(i)));
quote.setBookmark(Integer.parseInt(ar_bookmark.get(i)));
modelList.add(quote);
viewPagerAdapter = new ViewPagerAdapter(modelList,this);
viewPagerAdapter.notifyDataSetChanged();
viewPager.setAdapter(viewPagerAdapter);
if(getIntent().getIntExtra("id",0) != -1)
Bundle extras = getIntent().getExtras();
int pos = getIntent().getIntExtra("id",0);
Log.d(TAG, "pos"+pos);
viewPager.setCurrentItem(pos,true);
public class ViewPagerAdapter extends PagerAdapter
private List<Quote> quotesList;
private Context context;
private static final String TAG = "ViewPagerAdapter";
ImageButton imgshare,imgcopy,imgencshare,imgbookmark;
private MyDataBase db;
public ViewPagerAdapter(List<Quote> quotesList, Context context)
this.quotesList = quotesList;
this.context = context;
@Override
public int getCount()
return quotesList.size();
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o)
return view == (RelativeLayout) o;
@Override
public Object instantiateItem(ViewGroup container, final int position)
Log.d(TAG, "saiinstantiateItem: ");
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.viewpager_contents, container, false);
//container is a viewgroup.
TextView quotes = view.findViewById(R.id.quotes);
quotes.setText(quotesList.get(position).getQuote());
final String send = quotesList.get(position).getQuote();
db = new MyDataBase(context);
imgshare = (ImageButton) view.findViewById(R.id.btn_share);
imgcopy= (ImageButton) view.findViewById(R.id.btn_copy_quote);
imgencshare= (ImageButton) view.findViewById(R.id.btn_encrypt_and_share);
imgbookmark = (ImageButton) view.findViewById(R.id.btn_favorite);
// quotesList.get(position)
Log.d(TAG, "instantiateItemQuote: "+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
Log.d(TAG, "instantiateItem: "+quotesList.get(position).getBookmark());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
imgbookmark.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
// Log.d(TAG, "clicky"+quotesList.get(position).getId());
// Log.d(TAG, "clickycat"+quotesList.get(position).getCategory());
Log.d(TAG, "clickycat"+quotesList.get(position).getBookmark());
if(quotesList.get(position).getBookmark() == 1)
db.removeBookmark(quotesList.get(position).getCategory(),quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_black_24dp);
Toast.makeText(context, "Bookmark removed",
Toast.LENGTH_SHORT).show();
else
db.addBookmark(quotesList.get(position).getCategory(), quotesList.get(position).getId());
imgbookmark.setImageResource(R.drawable.ic_favorite_red_24dp);
Toast.makeText(context, "Bookmarked",
Toast.LENGTH_SHORT).show();
);
imgencshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String password = "password";
try
String encryptedMsg = AESCrypt.encrypt(password, send);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, encryptedMsg);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
catch (GeneralSecurityException e)
//handle error
);
imgcopy.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
String copytext;
copytext = send;
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(null, send);
if (clipboard == null) return;
clipboard.setPrimaryClip(clip);
Toast.makeText(context, "Text Copied",
Toast.LENGTH_SHORT).show();
);
imgshare.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, send);
sendIntent.setType("text/plain");
view.getContext().startActivity(Intent.createChooser(sendIntent,"choose app"));
);
container.addView(view);
return view;
@Override
public void destroyItem(ViewGroup container, int position, Object object)
container.removeView((View) object);
public int getItemPosition(Object object)
return POSITION_NONE;
java android
java android
asked Nov 11 '18 at 17:32
Air BenderAir Bender
12
12
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251367%2fupdate-image-in-page-of-viewpager-instantly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251367%2fupdate-image-in-page-of-viewpager-instantly%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown