Error:(136, 81) error: incompatible types: String cannot be converted to int
Error:(136, 81) error: incompatible types: String cannot be converted to int
我想在 listView
中显示进度条。下面的代码是 MyCustomBaseAdapter
.
的一部分
public class MyCustomBaseAdapter extends BaseAdapter{ // for ListView
private static ArrayList<SearchResults> searchArrayList;
RelativeLayout footerLayout;
private LayoutInflater mInflater;
ListView listview;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results,ListView listview,RelativeLayout footerLayout) {
searchArrayList = results;
this.listview=listview;
this.footerLayout=footerLayout;
mInflater = LayoutInflater.from(context);
addOrRemoveFooter();
}
public View getView(int position, View convertView, ViewGroup parent) {
final SearchResults search=getItem(position);
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtProject= (TextView) convertView.findViewById(R.id.ListProject);
holder.txtDescription = (TextView) convertView.findViewById(R.id.ListDescription);
//holder.txtProgress = (TextView) convertView.findViewById(R.id.ListProgress);
holder.progressBar=(ProgressBar)convertView.findViewById(R.id.downloadProgressBar);
holder.txtIn=(TextView)convertView.findViewById(R.id.ListTimeIn);
holder.txtOut=(TextView)convertView.findViewById(R.id.ListTimeOut);
holder.search = search;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtProject.setText(searchArrayList.get(position).getProject());
holder.txtDescription.setText(searchArrayList.get(position).getDescription());
//holder.txtProgress.setText(searchArrayList.get(position).getProgress());
holder.txtIn.setText(searchArrayList.get(position).getTimeIn());
holder.txtOut.setText(searchArrayList.get(position).getTimeOut());
holder.progressBar.setProgress(searchArrayList.get(position).getProgress()); // Error on this line setProgress(int) cannot be applied to java.lang.String
return convertView;
}
static class ViewHolder {
TextView txtProject;
TextView txtDescription;
TextView txtIn;
TextView txtOut;
ProgressBar progressBar;
SearchResults search;
}
}
搜索结果
private String progress="";
public void setProgress(String progress){
this.progress=progress;
}
public String getProgress()
{
return progress;
}
我得到这个错误是因为 setProgress
需要 int
但我在 get
和 setProgress
中有一个 String
数据类型。有没有我可以在不更改 SearchResults
中的数据类型的情况下解决错误行的问题?
how can I apply this to this line holder.progressBar.setProgress(searchArrayList.get(position).getProgress());
你可以使用 Integer.parseInt(String)
比如,
holder.progressBar.setProgress(
Integer.parseInt(searchArrayList.get(position).getProgress()));
解析值
根据您在下面的评论,拆分 String
然后取整数部分。像,
String str = searchArrayList.get(position).getProgress();
String[] arr = str.split(":\s*");
holder.progressBar.setProgress(Integer.parseInt(arr[1]));
我想在 listView
中显示进度条。下面的代码是 MyCustomBaseAdapter
.
public class MyCustomBaseAdapter extends BaseAdapter{ // for ListView
private static ArrayList<SearchResults> searchArrayList;
RelativeLayout footerLayout;
private LayoutInflater mInflater;
ListView listview;
public MyCustomBaseAdapter(Context context, ArrayList<SearchResults> results,ListView listview,RelativeLayout footerLayout) {
searchArrayList = results;
this.listview=listview;
this.footerLayout=footerLayout;
mInflater = LayoutInflater.from(context);
addOrRemoveFooter();
}
public View getView(int position, View convertView, ViewGroup parent) {
final SearchResults search=getItem(position);
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_row_view, null);
holder = new ViewHolder();
holder.txtProject= (TextView) convertView.findViewById(R.id.ListProject);
holder.txtDescription = (TextView) convertView.findViewById(R.id.ListDescription);
//holder.txtProgress = (TextView) convertView.findViewById(R.id.ListProgress);
holder.progressBar=(ProgressBar)convertView.findViewById(R.id.downloadProgressBar);
holder.txtIn=(TextView)convertView.findViewById(R.id.ListTimeIn);
holder.txtOut=(TextView)convertView.findViewById(R.id.ListTimeOut);
holder.search = search;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtProject.setText(searchArrayList.get(position).getProject());
holder.txtDescription.setText(searchArrayList.get(position).getDescription());
//holder.txtProgress.setText(searchArrayList.get(position).getProgress());
holder.txtIn.setText(searchArrayList.get(position).getTimeIn());
holder.txtOut.setText(searchArrayList.get(position).getTimeOut());
holder.progressBar.setProgress(searchArrayList.get(position).getProgress()); // Error on this line setProgress(int) cannot be applied to java.lang.String
return convertView;
}
static class ViewHolder {
TextView txtProject;
TextView txtDescription;
TextView txtIn;
TextView txtOut;
ProgressBar progressBar;
SearchResults search;
}
}
搜索结果
private String progress="";
public void setProgress(String progress){
this.progress=progress;
}
public String getProgress()
{
return progress;
}
我得到这个错误是因为 setProgress
需要 int
但我在 get
和 setProgress
中有一个 String
数据类型。有没有我可以在不更改 SearchResults
中的数据类型的情况下解决错误行的问题?
how can I apply this to this line
holder.progressBar.setProgress(searchArrayList.get(position).getProgress());
你可以使用 Integer.parseInt(String)
比如,
holder.progressBar.setProgress(
Integer.parseInt(searchArrayList.get(position).getProgress()));
解析值
根据您在下面的评论,拆分 String
然后取整数部分。像,
String str = searchArrayList.get(position).getProgress();
String[] arr = str.split(":\s*");
holder.progressBar.setProgress(Integer.parseInt(arr[1]));