开发者

problem with ListActivity

The following is my code for SettingsActivity.java. The main activity starts this activity by calling onScreenSettings(this)

public class SettingsActivity extends ListActivity{

static String[] main_settings = {"mode",
                            "timeout"
};
static String[] mode = { "Audio",
                  "Video",
                  "Audio/Video"
};
static String[] timeout = {
                        "1 min",
                        "5 min",
                        "10 min"
};
static String result;
static String[] display;

boolean settings_selected = false;
static String TAG = "****ALIST****";


public static void onScreenSettings(Activity c){

    display = main_settings;
    Log.d(TAG,"inside onScreenSettings");
    Intent intent = new Intent(c.getApplication(),SettingsActivity.class);
    try{
        c.startActivityForResult(intent,1);
        Log.d(TAG,"after starting activity in onScreenSettings");
    }catch(Exception e){

    }
}





@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Log.d(TAG,"inside onCreate-before setting listview");
    setListAdapter(new ArrayAdapter<String>(this,
               android.R.layout.simple_list_item_1, display));
        getListView().setTextFilterEnabled(true);
        Log.d(TAG,"inside oncreate-after setting listview");

}
public void onListItemClick(ListView l, View v, int position, long id){
     result = (String) l.getItemAtPosition(position);
     if(!settings_selected){
         if(result.equals("mode")){
        display = mode;         
         }
         else if(result.equals("timeout")){
        display = timeout;              
         }
         settings_selected = true;
         Log.d(TAG,"if !setting_selected");

     }
     else{/*accepting the sub options*/
         display = main_settings;//next the main settings must be displayed
         if(result.equals("Audio")){

         }
         else if(result.equals("Video")){
             Log.d(AndroidRecorder.TAG,"inside sub option Video");
         }
         else if(result.equals("Audio/Video")){

         }
         settings_selected = false;
         Log.d(TAG,"if setting_selected");
     }
     Intent intent = new Intent(this.getApplication(),SettingsActivity.class);
     try{
        startActivityForResult(intent,1);
        Log.d(TAG,"after starting activity in ListItemClick");
    }
    catch(Exception e){

    }

}
public void onActivityResult(int requestCode, int resultCode,Intent data) {
    //nothing to do with th开发者_Go百科e intent here
    Log.d(TAG,"inside onActivityResult");
    setResult(RESULT_OK, data);
    finish();
    Log.d(TAG,"inside onActivityResult-after finish()");
}
/*public void onBackPressed(){
    Log.d(TAG,"inside onBackPressed");
    finish();
    Log.d(TAG,"inside onBackPressed-after finish()");

}*/

}//end of ListActivity

Problem is control is not entering the else /*accepting the sub options*/ and I can't figure out why. As a result, the mode or timeout list is getting displayed again and again and the main_settings is not displayed. Please help.


When you call startActivityForResult in onListItemClick you get a whole new instance of the SettingsActivity. Does logcat show "inside oncreate" right after it shows "if !setting_selected"?

If it does and you don't want to go through major refactoring, you can stuff the value of setting_selected into an extra on the intent and pull it out in onCreate.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜