开发者

Get same status of checkbox in activity after reload of application

Hi I am new to android I would like to reload the same status when I restart application. my code snippets are: code for 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"  
/>

and I have ListActivity class called def code snippets are:

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();
        }
    }

thanks in advance


Persist the setting in a SharedPreferences file. And load the setting from the file in your activity's onResume() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜