list seems to be briefly shown again after selection
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开发者_Go百科 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.
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.
精彩评论