重新加载应用程序后,在活动中获取相同的复选框状态

时间:2011-04-02 06:32:34

标签: android listview android-listview

您好我是android新手我想在重新启动应用程序时重新加载相同的状态。 我的代码片段是: abc.xml的代码

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/title"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/textCheckMark"
    android:paddingLeft="6dip"
    android:paddingRight="6dip" 
    style="@style/CodeFont"  
/>

我有一个名为def code snippets的ListActivity类是:

import android.app.ListActivity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckedTextView;
import android.widget.ListView;
import android.widget.Toast;

public class def extends ListActivity {

    /** Called when the activity is first created. */
    static String[] value;
    MediaPlayer mediaPlayer = new MediaPlayer();    
    static int i=0;

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);     
        Bundle b = getIntent().getExtras();
                value = b.getStringArray("a1");
                this.setListAdapter(new ArrayAdapter<String>(this,R.layout.abc,value));
          }
@Override
    protected void onListItemClick(ListView l, View v, int position, long id) {             
        super.onListItemClick(l, v, position, id);              

        // Get the item that was clicked
        //Object o = this.getListAdapter().getItem(position);       

           //Generate and display the List of visits for this day by calling the AsyncTask


                      getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);               


        String keyword = value[position];

        mediaPlayer.reset();        
        try
        {
            mediaPlayer.setDataSource("/sdcard/"+keyword+".mp4");
            mediaPlayer.prepare();
            mediaPlayer.start();                            
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

提前致谢

1 个答案:

答案 0 :(得分:0)

将设置保留在SharedPreferences文件中。并在活动的onResume()方法中加载文件中的设置。