我正在使用custom list view
其中每一行包含两个图像视图和一个文本视图。我正在使用view holder
ingetView()
方法custom adapter
。我已经Onclicklistener()
在方法中设置了一个图像视图,getview()
也仅onSelectItemListener()
在listview
. 现在,当我点击imageview
它会影响特定的行,但是当我向下滚动时,我会得到随机行的影响。当我单击 On 时imageview
会发生这种情况但是当我不使用时不会发生这种情况viewholder
。我真的不明白为什么会这样。请帮我。
这是我的getView()
方法代码:
public View getView(int position, View convertView, ViewGroup parent) {
final int myposition = position;
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.fileviewrowfrnview_layout, null);
ViewHolder holder = new ViewHolder();
holder.icon = (ImageView) convertView.findViewById(R.id.icon2);
holder.text = (TextView) convertView.findViewById(R.id.file_name2);
holder.download = (ImageView) convertView.findViewById(R.id.play_buttonOropen2);
convertView.setTag(holder);
}
final ViewHolder holder = (ViewHolder) convertView.getTag();
holder.download.setOnClickListener(new View.OnClickListener() {
@
Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (frnshare_list.get(myposition).getFileType().trim()
.equalsIgnoreCase("file")) {
// it is file
if (frnshare_list.get(myposition).getDownloadStatus().trim()
.equalsIgnoreCase("0")) {
// is is not a downloaded file do download it
holder.icon.setVisibility(View.GONE);
holder.download.setVisibility(View.GONE);
holder.text.setTextSize(14);
Log.e("file to be download", "" + frnshare_list.get(myposition).getFileName());
if (frnshare_list.get(myposition).getFileName().length() > 15)
holder.text.setText(frnshare_list.get(myposition).getFileName().subSequence(0, 15) + " will be downloaded soon.");
else
holder.text.setText(frnshare_list.get(myposition).getFileName() + " will be downloaded soon.");
UserService us = new UserService(context);
Frnshared fdto = frnshare_list.get(myposition);
fdto.setDownloadStatus("2"); // in queue
fdto.setMessageId("0");
us.updateDowloadStatusById(fdto);
us.updatemsgIdbyId(fdto);
if (CommonUtility.isNetworkAvailable(context)) {
AsyncTask < Void, Void, Void > httpconnection = new AsyncTask < Void, Void, Void > () {@
Override
protected Void doInBackground(Void...params) {
// TODO Auto-generated method stub
NetworkCommunication nc = new NetworkCommunication(
context);
try {
UserService us = new UserService(
context);
Frnshared fdto = frnshare_list
.get(myposition);
Log.i("file to be download", "" + fdto.getFileName());
fdto.setDownloadStatus("2"); // in queue
fdto.setMessageId("0");
us.updateDowloadStatusById(fdto);
us.updatemsgIdbyId(fdto);
String response = nc
.MyHttpPostDownload(frnshare_list
.get(myposition));
ParsersAndDataInsertion.DownloadRequestResponseParser(
response, context,
frnshare_list.get(myposition));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// http call for download
return null;
}
}.execute(null, null, null);
}
Apitable(adto);
}
} else if (frnshare_list.get(myposition)
.getDownloadStatus().equalsIgnoreCase("1")) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(frnshare_list.get(myposition)
.getFileLocation());
intent.setDataAndType(Uri.fromFile(file), "audio/*");
context.startActivity(intent);
} else if (frnshare_list.get(myposition)
.getDownloadStatus().equalsIgnoreCase("2")) {
Toast.makeText(context, "already request snet", 2000)
.show();
}
} else if (frnshare_list.get(myposition).getFileType()
.equalsIgnoreCase("folder")) {}
}
});
// view purpose
String file_name = frnshare_list.get(position).getFileName();
if (file_name.length() > 15)
holder.text.setText(file_name.substring(0, 15) + "");
else
holder.text.setText(file_name); // frn name
try {
if (frnshare_list.get(myposition).getFileType()
.equalsIgnoreCase("file")) { // it is file
holder.icon.setImageResource(R.drawable.mp3_icon);
if (frnshare_list.get(myposition).getDownloadStatus()
.equalsIgnoreCase("0")) {
Log.i("file is ", "" + frnshare_list.get(myposition).getFileName());
holder.download.setImageResource(R.drawable.download_png);
} else if (frnshare_list.get(myposition).getDownloadStatus()
.equalsIgnoreCase("1")) {
} else if (frnshare_list.get(myposition).getDownloadStatus()
.equalsIgnoreCase("2")) {
Log.i("file is in queue", "" + frnshare_list.get(myposition).getFileName());
holder.icon.setVisibility(View.GONE);
holder.download.setVisibility(View.GONE);
holder.text.setTextSize(14);
if (frnshare_list.get(myposition).getFileName().length() > 15)
holder.text.setText(frnshare_list.get(myposition).getFileName().substring(0, 1);
else
holder.text.setText(frnshare_list.get(myposition).getFileName() );
}
} else if (frnshare_list.get(myposition).getFileType()
.equalsIgnoreCase("folder")) {
holder.icon.setImageResource(R.drawable.folder);
}
} catch (Exception e) {
// TODO: handle exception
Intent i = new Intent(context, TabViewActivity.class);
i.putExtra("show", "frntab");
context.startActivity(i);
BugSenseHandler.sendException(e);
e.printStackTrace();
}
return convertView;
}