相關元件有
FragmentTransaction 片段交易
Fragment 片段
DialogFragment 對話框片段
ListView點擊語法:
FragmentTransaction ft=getFragmentManager().beginTransaction(); Fragment prev=getFragmentManager().findFragmentByTag("dialog"); if(prev !=null){ ft.remove(prev); } ft.addToBackStack(null); TextView te1=(TextView)view.findViewById(R.id.text1); YNDialog newFragment=YNDialog.newInstance(te1.getText().toString()); newFragment.show(ft,"dialog");
對話框語法:
public class YNDialog extends DialogFragment { private String id_del; public Dialog onCreateDialog(Bundle bundle){ id_del=getArguments().getString("id"); AlertDialog.Builder builder =new AlertDialog.Builder(getActivity()); builder.setTitle(id_del+"資料是否刪除?"); builder.setPositiveButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //無動作 } }).setNegativeButton("刪除", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { SQLite2 del_sqlite2=(SQLite2)getActivity(); del_sqlite2.del(id_del); del_sqlite2.select(); } }); return builder.create(); } static YNDialog newInstance(String id){ YNDialog frag =new YNDialog(); Bundle args=new Bundle(); args.putString("id",id); frag.setArguments(args); return frag; }
教學影片:
沒有留言:
張貼留言
影片的問題請留在影片的留言區裡。
部落格不會另外通知給我,所以很難發現你有留言。