2012-03-06 8 views
0

私は、プロジェクト全体をActivityGroupsからFragmentsを使用して変換しようとしています。ここで アクティビティグループをフラグメントに変換する

は私の古いコードです:

SettingsActivityGroup

public class SettingsActivityGroup extends ActivityGroup 
{ 
// Keep this in a static variable to make it accessible for all the nested activities, lets them manipulate the view 
public static SettingsActivityGroup group; 

// Need to keep track of the history if you want the back-button to work properly, don't use this if your activities requires a lot of memory. 
private ArrayList<View> history; 

// Window focus changed listener 
public OnActivityGroupViewChanged activityGroupViewChangedListener = null; 

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    // Allocate history 
    this.history = new ArrayList<View>(); 

    // Set group 
    group = this;    

    // Start root (first) activity 
    Intent myIntent = new Intent(this, SettingsActivity.class); // Change to the first activity of your ActivityGroup 
    myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    ReplaceView("SettingsActivity", myIntent); 
} 

SettingsActivity

public class SettingsActivity extends Activity 
{ 
String[] settingsLabels = {"Viderestilling", "Voicemail", "Vis nummer", 
      "Kø styring", "Optag samtaler", "Services" }; 
ListView lv; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.settings); 
    lv = (ListView) findViewById(R.id.SettingsLV); 

    lv.setTextFilterEnabled(true); 

    populateListView(); 


} 

private void populateListView() 
{ 

     lv.setAdapter(new ArrayAdapter<String>(this, R.layout.settings_items, R.id.settings_item_label, settingsLabels)); 
     lv.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
      int position, long id) 
     { 
      // SwitchActivity(position); 
     } 
     }); 
} 

私が代わりに活性のListFragmentを拡張したい場合は - 私は変更するには何が必要ですすべてがまだ動作していることを確認するには?

答えて

0

Fragmentsのデベロッパーガイドの記事を見ましたか?私はそれがあなたの正確なユースケース(1つのフラグメント内の配列バックアップされたリストと別のフラグメントの詳細)を非常にほぼ描写していると思います。 APIDemosで完全なサンプル実装をチェックしてください。 API 4+ Support Demosにも下位互換性のあるバージョンがあります。

関連する問題