1
以下是SettingsActivity.java的代碼。主要活動通過調用onScreenSettings(本)啓動此活動ListActivity的問題
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 the 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
問題是控制不進入else /*accepting the sub options*/
,我想不通爲什麼。因此,模式或超時列表會一再顯示,並且main_settings不會顯示。 請幫忙。
顯示的活動org.example.AndroidRecorder/.SettingsActivity:489 ms(總計489 ms) D/**** ALIST ****(1538):if!setting_selected I/ActivityManager(971):開始活動:意圖{cmp = org.example.AndroidRecorder/.SettingsActivity} D/**** ALIST ****(1538):在ListItemClick中啓動活動之後 D/**** ALIST ****(1538) :在onCreate-before設置列表視圖 D/**** ALIST ****(1538):在內部創建 - 設置列表視圖之後 – Namratha 2010-07-07 08:09:23
這就是日誌顯示的內容,每次點擊列表中的任何項目 – Namratha 2010-07-07 08:10:25
謝謝!它工作。 – Namratha 2010-07-07 08:52:09