2011-05-14 51 views
-1

有人可以幫助我!我是新來的機器人,並開始我的第一個應用程序。列表似乎在選擇後再次簡要顯示

這個想法是從「main/first」活動開始第二個(列表活動),並將選定的對象返回到第一個活動。我正在使用一個處理程序來檢索類名稱列表(現在是從array.xml中),實例化這些類並將它們添加到數組中。我正在擴展陣列適配器來顯示它。

onActivityResult()在第一個活動中使用returnData.getParcelableExtra()來「重新充氣」所選項目對象。

一切正常,但從列表中選擇一個項目後,該列表似乎在返回到第一個活動之前再次顯示一秒鐘。這可能是正常的行爲,只是「感覺」,看起來不對。 我做錯了什麼?下面是該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 
} 

和處理程序的代碼...

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等

任何幫助將不勝感激。

回答

0

似乎問題不在代碼中,而是在佈局xml中爲列表中的行中的視圖。 我按照這個建議http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html它似乎已經解決了這個問題。沒有簡短的「重新呈現」清單。

+0

您應該接受自己的答案,因此您的問題將被標記爲「已回答」,其他人將知道問題已解決。 – Albireo 2011-05-26 09:10:38