以前に保存したデータに基づいて見られるように、アクティビティが最初に開かれたときにすべてのリストフラグメントが文法的に作成されるタブ付きアクティビティを作成しました。戻るボタンが押されたときにリストフラグメントのリロードを削除する
私は基本的にベースの活動から渡さバンドルデータに基づいて、私のSQLiteデータベースから、いくつかの特定の値を読んでいリスト断片で使用されている私の他のクラスで、その後public class CcSongBook extends ActionBarActivity implements TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
SharedPreferences vSettings;
SharedPreferences.Editor localEditor;
public SongBookSQLite db = new SongBookSQLite(this, SongBookDatabase.DATABASE, null, SongBookDatabase.VERSION);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sb_book);
vSettings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
localEditor = PreferenceManager.getDefaultSharedPreferences(this).edit();
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(2);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(this.mSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
}
}
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
String[] songbooks = TextUtils.split(vSettings.getString("js_vsb_sbcodes", "NA"), ",");
String[] songbookno = TextUtils.split(vSettings.getString("js_vsb_sbnos", "NA"), ",");
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return songbooks.length-1;
}
@Override
public CharSequence getPageTitle(int position) {
return songbooks[position];
}
public Fragment getItem(int position) {
Bundle data = new Bundle();
data.putInt("songbook", Integer.parseInt(songbookno[position]));
SongBookList sblist = new SongBookList();
sblist.setArguments(data);
return sblist;
}
}
public static class PlaceholderFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static PlaceholderFragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.sb_fragment, container, false);
return rootView;
}
}
}
:
今public class SongBookList extends ListFragment implements LoaderCallbacks<Cursor> {
public SongBookSQLite db;
private String[] My_Text, My_Texti, My_Textii;
List<SongItem> mylist;
ArrayAdapter<String> listAdapter;
SimpleCursorAdapter mCursorAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
db = new SongBookSQLite(getActivity().getBaseContext(), SongBookDatabase.DATABASE, null, SongBookDatabase.VERSION);
Bundle data = this.getArguments();
int curr_songbook = data.getInt("songbook", 1);
mylist = db.getAllSongs(curr_songbook);
List<String> listSongid = new ArrayList<String>();
List<String> listTitle = new ArrayList<String>();
List<String> listContent = new ArrayList<String>();
for (int i = 0; i < mylist.size(); i++) {
listSongid.add(i, Integer.toString(mylist.get(i).getSongid()));
listTitle.add(i, mylist.get(i).getTitle());
listContent.add(i, mylist.get(i).getContent());
}
My_Text = listSongid.toArray(new String[listSongid.size()]);
for (String string : My_Text) { System.out.println(string); }
My_Texti = listTitle.toArray(new String[listTitle.size()]);
for (String stringi : My_Texti) { System.out.println(stringi);}
My_Textii = listContent.toArray(new String[listContent.size()]);
for (String stringii : My_Textii) { System.out.println(stringii); }
setListAdapter(new CustomSongList(getActivity(), My_Text, My_Texti, My_Textii));
return super.onCreateView(inflater, container, savedInstanceState);
}
public void onStart() {
super.onStart();
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent myIntent = new Intent(getActivity().getApplicationContext(), SongBookView.class);
Uri data = Uri.withAppendedPath(SongBookProvider.CONTENT_URI, String.valueOf(id+1));
myIntent.setData(data);
startActivity(myIntent);
}
});
}
public Loader<Cursor> onCreateLoader(int arg0, Bundle data) {
Uri uri = SongBookProvider.CONTENT_URI;
return new CursorLoader(getContext(), uri, null, null, new String[]{data.getString("query")}, null);
}
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
this.mCursorAdapter.swapCursor(c);
}
public void onLoaderReset(Loader<Cursor> loader) {
}
ここでの主な問題は、私がreloadiから主な活動を防ぐどうすればよいです
public class SongBookView extends ActionBarActivity {
TextView mSongCont;
Cursor cursor;
public Uri mUri;
SongBookSQLite db;
SharedPreferences vSettings;
SharedPreferences.Editor localEditor;
String VSB_SETTINGS, FONT_SIZE, CURRENT_SONG;
public int CurrSong, FontSize;
ListView StanzasList;
SongItem currentSong;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.song_view);
db = new SongBookSQLite(this, SongBookDatabase.DATABASE, null, SongBookDatabase.VERSION);
StanzasList =(ListView)findViewById(R.id.stanzalist);
vSettings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
localEditor = PreferenceManager.getDefaultSharedPreferences(this).edit();
changeStatusBarColor();
Long rated_me_not = vSettings.getLong("js_vsb_rated_me_not", 0);
Long time_used = (System.currentTimeMillis() - rated_me_not)/1000;
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("js_vsb_rate_me", false)) {
if (time_used > 18000) {
rateMePlease();
}
}
FontSize = PreferenceManager.getDefaultSharedPreferences(this).getInt("js_vsb_font_size", 15);
mUri = getIntent().getData();
CurrSong = Integer.parseInt(mUri.toString().replaceAll("\\D+", ""));
openCurrentSong();
}
public void openCurrentSong(){
localEditor.putInt("js_vsb_curr_song", CurrSong).commit();
currentSong = db.readSong(CurrSong);
setTitle(currentSong.getTitle());
String[] Stanzas = TextUtils.split(currentSong.getContent(), "`");
CustomSongView adapter = new CustomSongView(this, Stanzas);
StanzasList.setAdapter(adapter);
}
@Override
public void onBackPressed() {
Intent intent = new Intent(this, CcSongBook.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
:リスト項目は、それが以下のように新しい活動に開きます任意のリスト断片上にクリックされましたそれが起こっているので、それ自体は何度も繰り返します。
おかげで、私の問題は解決しましたが、私はラインを必要と思いました intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);アプリから消費されるメモリを減らすように履歴からアクティビティをクリアできるようにする – Oyonde
私はそれがあなたがあなたのケーキを食べることができず、まだそれを持つことができないようなものであるため、まったく別のものが –
あなたの提案私のために働いた。 – Oyonde