2014-03-31 77 views
0

如何在onDialogPositiveClick中引用onListItemClick?所以頁面打開之前/對話框打開..我可以在OnDialogPositiveClick字面上onListItemClick,還是我必須做一些完全不同的事情?這是我的代碼...感謝所有/任何幫助!onListItemClick在onDialogPositiveClick?

public class MainActivity extends ListActivity implements TheDialog.NoticeDialogListener { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    //setContentView(R.layout.activity_main); 

    String[] sites = {"Google", "Amazon", "Ebay" , "Reddit", "SmashingMag", "CCC"}; 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.mylist_item, R.id.textView1, sites); 
    setListAdapter(adapter); 
} 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TODO Auto-generated method stub 
    super.onListItemClick(l, v, position, id); 
    DialogFragment newFragment = new TheDialog(); 
    newFragment.show(getFragmentManager(), "Confirm"); 
    Intent i = null; 
    switch(position){ 
    case 0: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
     startActivity(i); break; 
    case 1: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com")); 
     startActivity(i); break; 
    case 2: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ebay.com")); 
     startActivity(i); break; 
    case 3: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com")); 
     startActivity(i); break; 
    case 4: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.smashingmag.com")); 
     startActivity(i); break; 
    case 5: 
     i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.myccc.corning-cc.edu")); 
     startActivity(i); break; 
    } 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

@Override 
public void onDialogPositiveClick(DialogFragment dialog) { 
    // TODO Auto-generated method stub 
} 

@Override 
public void onDialogNegativeClick(DialogFragment dialog) { 
    // TODO Auto-generated method stub 

} 

} 

回答

0

你可以做不火列表項點擊意圖和撥碼開關移動到

onDialogPositiveClick(DialogFragment dialog){ 
Intent i = null; 
switch(position){ 
case 0: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
    startActivity(i); break; 
case 1: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.amazon.com")); 
    startActivity(i); break; 
case 2: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ebay.com")); 
    startActivity(i); break; 
case 3: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.reddit.com")); 
    startActivity(i); break; 
case 4: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.smashingmag.com")); 
    startActivity(i); break; 
case 5: 
    i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.myccc.corning-cc.edu")); 
    startActivity(i); break; 
}} 

這樣用戶只會去點擊肯定按鈕時,下一個頁面,希望你想要這種行爲。