选择后列表似乎再次短暂显示
有人可以帮我吗!我是 Android 新手,正在开始我的第一个应用程序。
这个想法是从“主/第一个”活动启动第二个(列表活动)并将选定的对象返回到第一个。我使用处理程序来检索类名称列表(现在从 array.xml 中),实例化类并将它们添加到数组中。我正在扩展数组适配器来显示它。
第一个活动中的 onActivityResult() 使用 returnData.getParcelableExtra() 来“重新膨胀”所选项目对象。
一切正常,但从列表中选择一个项目后,列表似乎会在返回第一个活动之前再次显示一瞬间。这可能是正常行为,只是“感觉”和看起来不对。 我做错了什么吗? 的代码
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent returnIntent = new Intent();
returnIntent.putExtra("my.source.selected", (Thing) this.getListAdapter().getItem(position));
setResult(RESULT_OK, returnIntent);
ExampleApplication application = (ExampleApplication) getApplication();
application.setCurrentlySelectedFormat(this.things.get(position));
finish(); //gives back the handle to parent activity
}
这是 onListItemClick()和处理程序
private final Handler handler = new Handler() {
public void handleMessage(final Message msg) {
super.handleMessage(msg);
progressDialog.dismiss();
if ((things == null || things.size() == 0)) {
empty.setText("No things found");
} else {
setListAdapter(new ThingAdapter(SelectThing.this, R.layout.row, things));
}
}
};
private void loadThings() {
if (things == null) {
final ThingFetcher ff = new ThingFetcher();
this.progressDialog = ProgressDialog.show(this, "Working...", " Retrieving things");
new Thread() {
public void run() {
things = ff.fetchFormats(SelectThing.this);
handler.sendEmptyMessage(0);
}
}.start();
}
}
@Override
protected void onResume() {
super.onResume();
loadThings();
}
...我的适配器已经过优化,似乎建议使用视图持有者并重新使用 ConvertView 等。
任何帮助将不胜感激。
Can somebody help me please! I'm new to android and am starting my first app.
The idea is to start a second (list activity) from a "main/first" activity and return a selected object back to the first. I'm doing this using a handler to retrieve the list of class names (from array.xml for now), instantiating the classes and adding them to the array. I'm extending array adapter to display it.
onActivityResult() in the first activity uses returnData.getParcelableExtra() to "re-inflate" the selected item object.
Everything works ok but after selecting an item from the list, the list seems to get shown again for a split second before returning to the first activity. This might be normal behaviour put it just "feels" and looks wrong.
Am I doing something wrong? Here's the code for the onListItemClick()
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent returnIntent = new Intent();
returnIntent.putExtra("my.source.selected", (Thing) this.getListAdapter().getItem(position));
setResult(RESULT_OK, returnIntent);
ExampleApplication application = (ExampleApplication) getApplication();
application.setCurrentlySelectedFormat(this.things.get(position));
finish(); //gives back the handle to parent activity
}
and for the handler...
private final Handler handler = new Handler() {
public void handleMessage(final Message msg) {
super.handleMessage(msg);
progressDialog.dismiss();
if ((things == null || things.size() == 0)) {
empty.setText("No things found");
} else {
setListAdapter(new ThingAdapter(SelectThing.this, R.layout.row, things));
}
}
};
private void loadThings() {
if (things == null) {
final ThingFetcher ff = new ThingFetcher();
this.progressDialog = ProgressDialog.show(this, "Working...", " Retrieving things");
new Thread() {
public void run() {
things = ff.fetchFormats(SelectThing.this);
handler.sendEmptyMessage(0);
}
}.start();
}
}
@Override
protected void onResume() {
super.onResume();
loadThings();
}
My adapter is optimised as seems to be recommended with view holder and re-using convertView etc.
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎问题不在代码中,而在列表行中视图的布局 xml 中。
我遵循了这个建议 http://android-developers.blogspot .com/2009/02/android-layout-tricks-1.html 似乎已经解决了问题。没有简短的“重新渲染”列表。
Seems the problem is not in the code but in the layout xml for the views in the rows in the list.
I followed this suggestion http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html and it seems to have fixed the problem. No brief "re-rendering" of the list.