- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现了一些类似的问题,但无法解决问题。我有一个自定义 ListView ,其中每个项目都包含一个水平进度条。但是当列表包含很多项目时,我使用滚动条在 ListView 中导航,一些 ProgressBars 消失了。是什么原因造成的,我该如何解决?我的代码在下面。提前谢谢。
public class ScrollActivity extends Activity {
ListView lv;
// ArrayList<String> list = new ArrayList<String>();
ArrayList<Url_Dto> list = new ArrayList<Url_Dto>();
MyListAdapter adtf;
public static String prf_date_view = "";
String str_start;
Button all_detail;
Button accepted_all, mainDownloadBtn;
Button not_shown;
public static SQLiteDatabase db;
String name;
File download;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll);
list = DBAdapter.getUrl_Detail();
Log.v("log_tag", "list :: " + list.size());
lv = (ListView) findViewById(R.id.main_list_meet);
mainDownloadBtn = (Button) findViewById(R.id.not_shown);
adtf = new MyListAdapter(this, 0, list);
lv.setAdapter(adtf);
/*SqliteAdpter dba = SqliteAdpter
.getAdapterInstance(getApplicationContext());
dba.createdatabase();
db = dba.openDataBase();*/
mainDownloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Log.v("log_tag","list.toArray() "+list.size() );
// new DownloadFileFromURL().equals(list.toArray());
}
});
}
public class MyListAdapter extends ArrayAdapter<Url_Dto> {
private LayoutInflater mInflater;
ArrayList<Url_Dto> emplist = null;
public Activity activity;
public MyListAdapter(Activity activity, int layoutResourceId,
ArrayList<Url_Dto> emplist) {
super(activity, layoutResourceId, emplist);
this.activity = activity;
this.emplist = emplist;
}
/*public MyListAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}*/
public int getCount() {
return list.size();
}
/*public Object getItem(int position) {
return position;
}*/
public long getItemId(int position) {
return position;
}
private class ListRowViews {
Button cl;
Button dl;
ProgressBar pr;
ImageView im;
};
public View getView(final int position, View convertView,
ViewGroup parent) {
final ListRowViews views;
final Url_Dto itemState = getItem(position);
// only recreate row if it is null
if (convertView == null) {
// store controls in tag of view so you can get them later
convertView = mInflater.inflate(R.layout.custome_list_view,null);
views = new ListRowViews();
views.cl = (Button) convertView
.findViewById(R.id.cancle_sedual);
views.dl = (Button) convertView
.findViewById(R.id.download_sedual);
views.pr = (ProgressBar) convertView
.findViewById(R.id.listprogressbar);
views.im = (ImageView) convertView
.findViewById(R.id.list_image);
views.im.setImageResource(emplist.get(position).images[position]);
views.cl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.GONE);
itemState.isClicked = true;
}
});
views.dl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
str_start = emplist.get(position).url_video;
views.dl.setVisibility(View.GONE);
views.cl.setVisibility(View.VISIBLE);
Log.v("log_tag", "str_start " + str_start);
//
// new DownloadFileFromURL().execute(str_start);
new DownloadFileFromURL().execute(views.pr, str_start);
}
});
// store the view pointers for reuse later
convertView.setTag(views);
} else {
views = (ListRowViews) convertView.getTag();
}
// you need to get the progress from list item that this view
// represents
int progress = itemState.progress;
views.pr.setProgress(progress);
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.VISIBLE);
if (itemState.isVisible) {
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.GONE);
} else {
views.dl.setVisibility(View.GONE);
views.cl.setVisibility(View.VISIBLE);
}
return convertView;
}
}
class DownloadFileFromURL extends AsyncTask<Object, String, String> {
int count = 0;
ProgressDialog dialog;
ProgressBar progressBar;
int myProgress;
/**
* Before starting background thread Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
ProgressBar progressBar;
}
/**
* Downloading file in background thread
* */
@Override
protected String doInBackground(Object... params) {
Log.v("log_tag", "params :::; " + params);
int count;
progressBar = (ProgressBar) params[0];
try {
// URL url = new URL(f_url[0]);
URL url = new URL((String) params[1]);
Log.v("log_tag", "name ::: " + url);
name = ((String) params[1]).substring(((String) params[1])
.lastIndexOf("/") + 1);
Log.v("log_tag", "name Substring ::: " + name);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();
// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(),
8192);
download = new File(Environment.getExternalStorageDirectory()
+ "/download/");
if (!download.exists()) {
download.mkdir();
}
String strDownloaDuRL = download + "/" + name;
Log.v("log_tag", " down url " + strDownloaDuRL);
FileOutputStream output = new FileOutputStream(strDownloaDuRL);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
// publishProgress("" + (int) ((total * 100) /
// lenghtOfFile));
// writing data to file
progressBar
.setProgress((int) ((total * 100) / lenghtOfFile));
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
Log.v("log_tag", "progress :: " + values);
// setting progress percentage
// pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
Log.v("log", "login ::: 4::: " + download);
String videoPath = download + "/" + name;
String chpName = name;
Log.v("log_tag", "chpName ::::" + chpName + " videoPath "
+ videoPath);
/*db.execSQL("insert into videoStatus (chapterNo,videoPath) values(\""
+ chpName + "\",\"" + videoPath + "\" )");
*/
}
}
}
当进度条状态不可见且按钮状态隐藏时,我尝试向上滚动。问题是什么以及如何解决?
我的错误 Given it::
02-20 18:44:39.640: E/AndroidRuntime(4144): FATAL EXCEPTION: main
02-20 18:44:39.640: E/AndroidRuntime(4144): java.lang.NullPointerException
02-20 18:44:39.640: E/AndroidRuntime(4144): at com.example.testscrollup.ScrollActivity$MyListAdapter.getView(ScrollActivity.java:121)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.AbsListView.obtainView(AbsListView.java:1593)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.ListView.makeAndAddView(ListView.java:1782)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.ListView.fillDown(ListView.java:705)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.ListView.fillFromTop(ListView.java:762)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.ListView.layoutChildren(ListView.java:1633)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.AbsListView.onLayout(AbsListView.java:1423)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.View.layout(View.java:7175)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.View.layout(View.java:7175)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.View.layout(View.java:7175)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.View.layout(View.java:7175)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.View.layout(View.java:7175)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.os.Looper.loop(Looper.java:130)
02-20 18:44:39.640: E/AndroidRuntime(4144): at android.app.ActivityThread.main(ActivityThread.java:3687)
02-20 18:44:39.640: E/AndroidRuntime(4144): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 18:44:39.640: E/AndroidRuntime(4144): at java.lang.reflect.Method.invoke(Method.java:507)
02-20 18:44:39.640: E/AndroidRuntime(4144): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
02-20 18:44:39.640: E/AndroidRuntime(4144): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
02-20 18:44:39.640: E/AndroidRuntime(4144): at dalvik.system.NativeStart.main(Native Method)
我使用了下面给出的 Url_dto 类代码::
public class Url_Dto {
String url_video;
Integer[] images = { R.drawable.alligator_sm,
R.drawable.bear_sm, R.drawable.bee_sm, R.drawable.bluejay_sm,
R.drawable.camel_sm, R.drawable.cat_sm, R.drawable.chimpanzee_sm,
R.drawable.chipmunk_sm, R.drawable.cheetah_sm, R.drawable.cock_sm,
R.drawable.cow_sm, R.drawable.coyote_sm, R.drawable.deer_sm,
R.drawable.dog_sm };
protected boolean isClicked;
public int progress;
public boolean isVisible;
}
我的 DBADpter 类如下所示::::
public class DBAdapter {
public static String url = "***** My Url ********";
public static ArrayList<Url_Dto> getUrl_Detail() {
ArrayList<Url_Dto> fetchUrl_Detail = new ArrayList<Url_Dto>();
String result = "";
InputStream is = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
// http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// parse json data
try {
JSONObject json_obj = new JSONObject(result);
JSONArray j_Arr_fn = json_obj.getJSONArray("children");
for (int i = 0; i < j_Arr_fn.length(); i++) {
JSONObject json_objs = j_Arr_fn.getJSONObject(i);
Url_Dto proDto = new Url_Dto();
proDto.url_video = json_objs.getString("videoUrl");
Log.v("log_tag", "Url :::" + json_objs.getString("videoUrl"));
fetchUrl_Detail.add(proDto);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
return fetchUrl_Detail;
}
}
最佳答案
当您向上或向下滚动以节省内存时,android 系统会重用行项目。
所以当你点击一行中的一个控件时,它被设置为 Visibility.GONE,然后当你滚动时,相同的控件在其他列表项上不可见,因为进度条之前设置为不可见 -明白了吗?
此外,每次显示时您都在重新创建 View ,因此您正在创建新的进度条,而不是重复使用已创建的进度条。
您只需创建一次控件,并在每次显示控件时重置控件的可见性和状态。
使用容器类来保存指向已创建 View 的指针,这样您就不必每次都重新创建它们。
private class ListRowViews
{
Button c1;
Button d1;
ProgressBar pr;
};
public View getView(final int position, View convertView, ViewGroup parent)
{
ListRowViews views;
final YourStateClass itemState = getItem(position);
//only recreate row if it is null
if (convertView == null)
{
//store controls in tag of view so you can get them later
convertView = mInflater.inflate(R.layout.custome_list_view, null);
views = new ListRowViews();
views.cl = (Button) convertView.findViewById(R.id.cancle_sedual);
views.dl = (Button) convertView.findViewById(R.id.download_sedual);
views.pr=(ProgressBar)convertView.findViewById(R.id.listprogressbar);
views.cl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.GONE);
itemState.isClicked = true;
}
});
views dl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
str_start=list.get(position).url_video;
views.dl.setVisibility(View.GONE);
views.cl.setVisibility(View.VISIBLE);
Log.v("log_tag","str_start "+ str_start);
//
//new DownloadFileFromURL().execute(str_start);
new DownloadFileFromURL().execute(pr,str_start);
}
});
//store the view pointers for reuse later
convertView.setTag(views);
}
else
{
views = (ListRowViews)convertView.getTag();
}
//you need to get the progress from list item that this view represents
int progress = itemState.progress;
views.pr.setProgress(progress);
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.VISIBLE);
if (itemState.isVisible)
{
views.dl.setVisibility(View.VISIBLE);
views.cl.setVisibility(View.GONE);
}
else
{
views.dl.setVisibility(View.GONE);
views.cl.setVisibility(View.VISIBLE);
}
return convertView;
}
关于android - 向上滚动时自定义 ListView 然后隐藏进度条进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14957326/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!