edd*_*ddy 7 layout android refresh android-listview
我使用下面的代码:
private Runnable returnRes = new Runnable() {
@Override
public void run() {
if(m_orders != null && m_orders.size() > 0){
m_adapter.notifyDataSetChanged();
for(int i=0;i<m_orders.size();i++)
m_adapter.add(m_orders.get(i));
}
m_ProgressDialog.dismiss();
m_adapter.notifyDataSetChanged();
}
};
Run Code Online (Sandbox Code Playgroud)
但奇怪的是,在列表填充之后,唯一可用的项目是列表中的第一件事,直接在下面的行将是空的,除非我向下拖出视图然后再返回然后它显示.我非常确定上面的代码是正确的,因为我遵循了一个教程.但是,我不能指望用户再次向下拖动以查看所涉及的内容......
另外,我只是注意到我的数据没有正确填充,因为这个警告会出现07-19 23:54:49.947: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44eb97c0
,我很确定我的代码是正确的,以下是它停止的地方:
public View getView(int position, View convertView, ViewGroup parent){
View v = convertView;
if(v != null){
return v;
}
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
Log.d("added", "g" + position);
Grade g = grades.get(position);
if(g != null){
TextView name = (TextView) findViewById(R.id.bottomtext);
TextView id = (TextView) findViewById(R.id.toptext);
if(name != null)
name.setText(g.getName());
if(id != null)
id.setText(g.getId());
Log.d("grade", "grade " + g.toString());
}
return v;
}
Run Code Online (Sandbox Code Playgroud)
从LogCat跟踪我只能到达位置3 :(可能是什么问题?有人请帮帮我...
LoginByHttpPost gradeIndex = new LoginByHttpPost();
HttpURLConnection gradePage = gradeIndex.doHttpGet(TARGETURL);
String gradeInd = gradeIndex.readResponse(gradePage);
Document doc = Jsoup.parse(gradeInd);
// do more things here
Log.d("grade now ", grades.get(0).text());
Log.d("gradef now ", gradesF.text());
for(int i = 0; i < grades.size(); i += 5){
Grade grade = new Grade();
grade.setId(grades.get(i).text());
grade.setName(grades.get(i + 1).text());
//gradeList.add(grade);
ga.add(grade); //this is my arrayadapter not sure where to add my object to through :(
}
for(int i = 0; i < gradesF.size(); i++){
gradeList.get(i).setGrade(gradesF.get(i).text());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("prob", e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
这是从函数doInBackground()中的asyncatask调用的
尝试在列表视图上调用ListView.invalidateViews().为我工作.
即使从适配器上的UI线程调用notifyDataSetChanged()和/或notifyDataSetInvalidated(),这些也只会使数据无效,而不会使视图无效.因此.
小智 5
你应该notifyDataSetChanged()在UI线程中调用try尝试runOnUiThread().第二件事是notifyDataSetChanged()应该在添加,删除和清除功能之后调用.