In my application I have used ImageView inside the HorizontalScrollView . ImageView images are getting from URI(json parsing),and the images are loaded to ImageView using universal image loader.
Here my problem is how to change the ImageView background for corresponding image on item click.
thanks in advance
what I have to tried:
String RecentBooks="http://";
ArrayList<List<String>> arrrecentbooks= new ArrayList<List<String>> ();
//HorizontalScrollview created programaticallly
HorizontalScrollView scollviewh = new HorizontalScrollView(this);
View v1=null;
LinearLayout linear_pmain = new LinearLayout(this);
linear_pmain.setOrientation(LinearLayout.HORIZONTAL);
// linear_pmain.setBackgroundDrawable(getResources().getDrawable(R.drawable.topshelf));bottomthumbnail
//arrrecentbook contains images parsed fron uri
int length=arrrecentbooks.size();
for(int j=0;j<length;j++)
{
LayoutInflater vii = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v1=vii.inflate(R.layout.thumbnailrowlayout, null);
List<String> listitem=arrrecentbooks.get(j);
String rimageurl=listitem.get(13);
String rbookprice=listitem.get(10);
img=(ImageView) v1.findViewById(R.id.imgg);
TextView txt=(TextView) v1.findViewById(R.id.txtg);
txt.setText("Rs."+rbookprice+"/-");
txt.setTypeface(tf,Typeface.NORMAL);
img.setTag(new String[]{listitem.get(0),listitem.get(1),listitem.get(2),listitem.get(3),listitem.get(4),listitem.get(5),listitem.get(6),listitem.get(7),listitem.get(8),listitem.get(9),listitem.get(10),listitem.get(11),listitem.get(12),listitem.get(13),listitem.get(14),listitem.get(15),listitem.get(16),listitem.get(17),listitem.get(18),listitem.get(19),listitem.get(20),"recentbooks"});
//image loaded to image view
{
imageLoader=new ImageLoader(this);
imageLoader.DisplayImage(rimageurl, this, img);
}
img.setOnClickListener(myIItemClickListener);
linear_pmain.addView(v1);
}
scollviewh.addView(linear_pmain);
lrecentbooks.addView(scollviewh);
//imgeview on itemclick listener
public OnClickListener myIItemClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
try{
RelativeLayout borderlyt=(RelativeLayout)findViewById(R.id.Booklyut);
borderlyt.setBackgroundResource(R.drawable.bgorange);
String[] Qtag = (String[]) v.getTag();
Log.d("myItemClickListener", Qtag + "");
//v.setBackgroundResource(R.drawable.bgorange);
Intent itemintent = new Intent(cxt,NoolDashboardDetailPage.class);
Bundle b = new Bundle();
b.putStringArray("iarray", Qtag);
b.putInt("mflag", 0);
itemintent.putExtra("android.intent.extra.INTENT", b);
startActivityForResult(itemintent,2);
}
catch (Exception e) {
// TODO: handle exception
}
}
};
I believe you would like to highlight the images when touched?
Try the following below your img.setOnClickListener(myIItemClickListener);:
img.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent e) {
if (e.getAction() == MotionEvent.ACTION_DOWN) {
((ImageView) v).setColorFilter(0x44E79B0E, PorterDuff.Mode.SRC_ATOP);
}
if ((e.getAction() == MotionEvent.ACTION_UP) || (e.getAction() == MotionEvent.ACTION_CANCEL)) {
((ImageView) v).setColorFilter(null);
}
return false;
}
});
Change '0x44E79B0E' to your desired transparent color.
Let me know, if it works for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With