0

我需要在屏幕旋轉後保存ID。 (Android 3.2+)。 Deatils: 在清單:旋轉後保留視圖ID

android:configChanges="orientation|screenSize" 

在活動時間:

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    // TODO Auto-generated method stub 
    super.onConfigurationChanged(newConfig); 
    initializeAnimation(true); 
    if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { 
     refreshView(true); 
    } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     refreshView(false); 
    } 
} 

refreshView方法獲取ListView的集合或其他類GridView的收集和投入ViewFlipper。用戶可以觸摸列表或網格視圖中的元素,並開始在AsyncTask中和所選元素顯示的進度條中下載。

型號:

public List<ListView> getListViews(Context c) { 
    listViews.clear(); 
    Iterator<List<Map<String, String>>> iter = arr.iterator(); 
    while (iter.hasNext()) { 
     SimpleAdapter a = new SimpleAdapter(c, iter.next(), R.layout.vertical_list_view_item, new String[] { MONTH, IMAGE, DESCRIPTION}, new int[] { R.id.txtMonthV , R.id.imgV, R.id.txtDecriptionV}); 
     ListView lv = new ListView(c); 
     lv.setDivider(null); 
     lv.setDividerHeight(0); 
     lv.setAdapter(a); 
     listViews.add(lv); 
    } 
    return listViews; 
} 

public List<GridView> getGridViews(Context c){ 
    List<GridView> gridViews = new ArrayList<GridView>(); 
    Iterator<List<Map<String, String>>> iter = arr.iterator(); 
    while (iter.hasNext()) { 
     SimpleAdapter a = new SimpleAdapter(c, iter.next(), R.layout.horizontal_list_view_item , new String[] { MONTH, IMAGE/*, DESCRIPTION*/}, new int[] { R.id.txtMonthH, R.id.imgH/*, R.id.txtDescriptionH*/ }); 
     GridView gv = new GridView(c); 
     gv.setHorizontalSpacing(15); 
     gv.setVerticalSpacing(15); 
     gv.setNumColumns(6); 
     gv.setAdapter(a); 
     gridViews.add(gv); 
    } 

    return gridViews;  
} 

位指示:

public View currentView; 

public View getCurrentPressedView(){ 
    return currentView; 
} 

public void setCurrentPressedView(View v){ 
    currentView = v; 
} 



@Override 
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { 
    if (arg0 instanceof ListView) { 
     /*....*/ 
     setCurrentPressedView(arg1); 
     //Start download here 
    } else if (arg0 instanceof GridView) { 
     /*...*/ 
     setCurrentPressedView(arg1); 
     //Start download here 
    } 
} 

在異步任務:

View view; 
ProgressBar proBar; 
@Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
     view = getCurrentPressedView(); 
     proBar = (ProgressBar) view.findViewById(R.id.progress); 
     proBar.setVisibility(View.VISIBLE); 
///..... 
@Override 
    protected void onProgressUpdate(Integer... values) { 
     mProDialog.setProgress(values[0]); 
     proBar.setVisibility(View.VISIBLE); 
     super.onProgressUpdate(values); 
    } 

在vertical_list_view_item和horizo​​ntal_list_view_item進度條具有相同的ID。 但是當屏幕旋轉時,ID改變,我無法控制進度條。有人能幫助我嗎? Thx

回答

0

你使用了一個靜態變量來存儲ID嗎?

+0

不,編號在屏幕旋轉後發生變化,因爲我們獲得了其他網格視圖或列表視圖集合。 –