如何在onDialogPositiveClick中引用onListItemClick?因此页面在对话框打开之前/之前没有打开。我可以在onDialogPositiveClick上放置onListItemClick,或者我必须做一些完全不同的事情吗?这是我的代码...感谢所有/任何帮助!
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 :(得分: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;
}}
这样用户只有在点击正面按钮时才会进入下一页,希望你想要这种行为。