在Android中单击时更改Listview项目图像
我想在单击nect和prev按钮时更改特定的列表视图图像,但在单击next和prev按钮时更改所有列表视图图像在Android中单击时更改Listview项目图像,android,listview,android-lazyloading,Android,Listview,Android Lazyloading,我想在单击nect和prev按钮时更改特定的列表视图图像,但在单击next和prev按钮时更改所有列表视图图像 public class ListAdapter extends ArrayAdapter<String>{ Context context; String imgurl; String[] imageUrls; int i=1; ViewHolder holder = null; ArrayList<Str
public class ListAdapter extends ArrayAdapter<String>{
Context context;
String imgurl;
String[] imageUrls;
int i=1;
ViewHolder holder = null;
ArrayList<String> strimgview,strstreetname,strLocation,strSquarefootage,strPrice,strPosted,strURL,strId;
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true).build();
public ListAdapter(Context context,ArrayList<String> strimgview, ArrayList<String> strstreetname,
ArrayList<String> strLocation,ArrayList<String> strSquarefootage,
ArrayList<String> strPrice,ArrayList<String> strPosted,
ArrayList<String> strId,ArrayList<String> strURL)
{
super(context, R.layout.propertyrow,strstreetname);
this.context= context;
this.strimgview= strimgview;
this.strstreetname= strstreetname;
this.strLocation= strLocation;
this.strSquarefootage= strSquarefootage;
this.strPrice= strPrice;
this.strPosted= strPosted;
this.strURL= strURL;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View row = convertView;
if (row == null) {
row=mInflater.inflate(R.layout.propertyrow, parent,false);
holder = new ViewHolder();
holder.imgProperty =(ImageView) row.findViewById(R.id.npTupleImage);
holder.txtStreetName= (TextView) row.findViewById(R.id.npTupleProjectName);
holder.txtLocation= (TextView) row.findViewById(R.id.npTupleBuilder);
holder.txtSquareFotage= (TextView) row.findViewById(R.id.npTupleProjectAddress);
holder.txtPrice =(TextView) row.findViewById(R.id.npTupleProjectDistance);
holder.txtprev =(TextView) row.findViewById(R.id.prev);
holder.txtnext =(TextView) row.findViewById(R.id.next);
//txtprev.setVisibility(View.INVISIBLE);
//txtnext.setVisibility(View.INVISIBLE);
holder.imglike= (ImageView) row.findViewById(R.id.unsavebtn);
holder.imglike.setVisibility(View.INVISIBLE);
row.setTag(holder);
}
else {
holder = (ViewHolder) row.getTag();
}
// txtposted.setText("EnteredDate :"+strPosted.get(position));
holder.txtStreetName.setText("Street Name :"+strstreetname.get(position));
holder.txtLocation.setText("Location :"+strLocation.get(position));
holder.txtSquareFotage.setText("SquareFootage :"+strSquarefootage.get(position));
holder.txtPrice.setText("Price :$"+strPrice.get(position));
holder.imgProperty.setTag(position);
// Log.d("Img",strimgview.get(position));
try{
// ArrayList<String> imgurl=new ArrayList<String>();
imgurl= ""+strimgview.get(position);
imageUrls=imgurl.split("\\|\\|");
for(int j=0;j<imageUrls.length-1;j++)
imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);
}
catch(Exception e)
{
Toast.makeText(context, "Load"+e, Toast.LENGTH_LONG).show();
}
holder.imglike.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText(context, "Want to save", Toast.LENGTH_LONG).show();
}
});
holder.txtprev.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(i!=1)
{
i--;
imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);
Log.d("imageUrlnew ",imageUrls[i]);
}
}
catch(Exception e)
{
// Toast.makeText(context, "next"+e, Toast.LENGTH_LONG).show();
}
notifyDataSetChanged();
}
});
holder.txtnext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if((i<imageUrls.length-1))
{
i++;
imageLoader.displayImage(imageUrls[i], holder.imgProperty, options);
Log.d("imageUrlnew ",imageUrls[i]);
}
}
catch(Exception e)
{
// Toast.makeText(context, "prev"+e, Toast.LENGTH_LONG).show();
}
notifyDataSetChanged();
}
});
return row;
}
class ViewHolder {
ImageView imgProperty;
TextView txtprev,txtnext;
TextView txtStreetName;
TextView txtLocation;
TextView txtSquareFotage;
TextView txtPrice;
ImageView imglike;
ProgressBar progressBar;
}
}
公共类ListAdapter扩展了ArrayAdapter{
语境;
字符串imgurl;
字符串[]图像URL;
int i=1;
ViewHolder=null;
ArrayList strimgview、strstreetname、strLocation、strSquarefootage、strPrice、strPosted、strURL、strId;
ImageLoader ImageLoader=ImageLoader.getInstance();
DisplayImageOptions=new DisplayImageOptions.Builder().cacheInMemory(true)
.cacheOnDisc(true).resetViewBeforeLoading(true).build();
公共ListAdapter(上下文上下文、ArrayList strimgview、ArrayList strStrStreetName、,
ArrayList strLocation,ArrayList strSquarefootage,
ArrayList strPrice,ArrayList strpoted,
ArrayList strId,ArrayList strURL)
{
super(context,R.layout.propertyrow,strstreetname);
this.context=context;
this.strimgview=strimgview;
this.strstrestreetname=strstrstrestreetname;
这个.strLocation=strLocation;
this.strSquarefootage=strSquarefootage;
this.strPrice=strPrice;
this.strPosted=strPosted;
这个.strURL=strURL;
}
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutInflater mInflater=(LayoutInflater)context.getSystemService(Activity.LAYOUT\u INFLATER\u SERVICE);
视图行=转换视图;
if(行==null){
row=mInflater.充气(R.layout.propertyrow,父项,false);
holder=新的ViewHolder();
holder.imgProperty=(ImageView)row.findViewById(R.id.npTupleImage);
holder.txtStreetName=(TextView)row.findViewById(R.id.npTupleProjectName);
holder.txtLocation=(TextView)row.findViewById(R.id.npTupleBuilder);
holder.txtSquareFotage=(TextView)row.findViewById(R.id.npTupleProjectAddress);
holder.txtPrice=(TextView)row.findViewById(R.id.npTupleProjectDistance);
holder.txtprov=(TextView)row.findViewById(R.id.prev);
holder.txtnext=(TextView)row.findViewById(R.id.next);
//txtprov.setVisibility(视图不可见);
//setVisibility(View.INVISIBLE);
holder.imglike=(ImageView)row.findViewById(R.id.unsavebtn);
holder.imglike.setVisibility(视图.不可见);
row.setTag(支架);
}
否则{
holder=(ViewHolder)row.getTag();
}
//setText(“EnteredDate:+strPosted.get(position));
holder.txtStreetName.setText(“街道名称:”+strstrestreetname.get(位置));
holder.txtLocation.setText(“位置:+strLocation.get(位置));
holder.txtSquareFotage.setText(“平方英尺:+strSquarefootage.get(位置));
holder.txtPrice.setText(“价格:$”+strPrice.get(位置));
holder.imgProperty.setTag(位置);
//Log.d(“Img”,strimgview.get(position));
试一试{
//ArrayList imgurl=新的ArrayList();
imgurl=”“+strimgview.get(位置);
imageUrls=imgurl.split(“\\\\\\\\\\\”);
对于(int j=0;j这不是一个完美的解决方案,如果它按照您的要求工作。然后在不切换开关的情况下更新解决方案
lstviewHomeList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
switch (position) {
case 0:
Button btnprev = (Button ) arg1.findViewById(R.id.button_id);
//same for image and any widgetn your adapter layout xml
btnprev.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//do what u want
}
});
break;
default:
break;
}
}
});
lstviewHomeList.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
公共单击(适配器视图arg0,视图arg1,内部位置,
长arg3){
开关(位置){
案例0:
按钮btnprev=(按钮)arg1.findViewById(R.id.Button\u id);
//对于适配器布局xml中的图像和任何widgetn,也是如此
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图arg0){
//做你想做的
}
});
打破
违约:
打破
}
}
});
但如何识别列表项我可以获取特定列表项的图像url,但我不知道如何使用switch rite?在avtivity中更改ONclickr u上的特定列表项图像。@MSGadag否我没有使用switch Ritu r在您的活动中没有使用listview?