java - How to show alertdialog before asynctask start -
i want show alertdialog , input user , after that, processing inputs in asynctask alertdialog become dismissed before inputs , asynctask start execute.
what should do? please me. here code;
private string[] newspapers,newspapersurl,newspaperspath; private string[] choosed,choosedurl,choosedpath; private boolean[] checked; private int pernewspaper; private boolean returned = false; private alertdialog.builder builder; private fetchingnewsbychoice fetchingnewsbychoice; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); returned = alertdialogcreation(); if(returned) { fetchingnewsbychoice = new fetchingnewsbychoice((appcompatactivity)mainactivity.this,choosed,choosedpath,pernewspaper); fetchingnewsbychoice.execute(); } floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { snackbar.make(view, "replace own action", snackbar.length_long) .setaction("action", null).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } //***** alert dialog *****// public boolean alertdialogcreation() { //***** file control , creating dialog interface if first usage *****// file file = getapplicationcontext().getfilestreampath("first.txt"); if(!file.exists()) { writetofile("first.txt", "0",true); } if(readfromfile("first.txt",false)[0].equals("0")) { newspapers = readfromfile("choicable newspaper.txt",true); newspapersurl = readfromfile("choicable url.txt",true); newspaperspath = readfromfile("choicable path.txt",true); checked = new boolean[newspapers.length]; builder = new alertdialog.builder(this,r.style.appcompatalertdialogstyle); builder.settitle("lütfen güncel haberlerini takip etmek İstediğiniz siteleri seçiniz.."); builder.setitems(newspapers, null); builder.setpositivebutton("tamam", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialoginterface, int i) { int count = 0; (int = 0; < newspapers.length; a++) { if (checked[a]) { count++; writetofile("choosed.txt", newspapers[a], false); writetofile("choosedurl.txt", newspapersurl[a], false); writetofile("choosedpath.txt", newspaperspath[a], false); } if (a == (newspapers.length - 1) && count == 0) { toast.maketext(getapplicationcontext(), "en az bir gazete seçmek zorundasınız..", toast.length_long).show(); builder.show(); } } } }); builder.setmultichoiceitems(newspapers, checked, new dialoginterface.onmultichoiceclicklistener() { @override public void onclick(dialoginterface dialoginterface, int i, boolean ischecked) { if (ischecked) { checked[i] = true; } else { checked[i] = false; } } }); try { builder.show(); } catch (exception ex) { ex.printstacktrace(); } writetofile("first.txt", "1", true); choosed = readfromfile("choosed.txt",false); choosedurl = readfromfile("choosedurl.txt",false); choosedpath = readfromfile("choosedpath.txt",false); if(choosed != null) { pernewspaper = (int) math.ceil(newspapers.length / choosed.length); if(pernewspaper > 15) { pernewspaper = 14; } } return true; } else if(readfromfile("first.txt",false)[0].equals("1")) { newspapers = readfromfile("choicable newspaper.txt",true); newspapersurl = readfromfile("choicable url.txt",true); newspaperspath = readfromfile("choicable path.txt",true); choosed = readfromfile("choosed.txt",false); choosedurl = readfromfile("choosedurl.txt",false); choosedpath = readfromfile("choosedpath.txt",false); pernewspaper = (int) math.ceil(newspapers.length / choosed.length); if(pernewspaper > 15) { pernewspaper = 14; } return true; } else { return false; } //***** file control , creating dialog interface if first usage *****// } //*****files*****// private void writetofile(string filename,string data,boolean isprivate) { try { outputstreamwriter outputstreamwriter; if(isprivate) { outputstreamwriter = new outputstreamwriter(getapplicationcontext().openfileoutput(filename, mode_private)); } else { outputstreamwriter = new outputstreamwriter(getapplicationcontext().openfileoutput(filename, mode_append)); } outputstreamwriter.write(data+"\r\n"); outputstreamwriter.close(); } catch (ioexception e) { } } public string[] readfromfile(string filename,boolean isasset) { string[] ret=null; try { inputstream inputstream; if(isasset) { inputstream = getapplicationcontext().getassets().open(filename); } else { inputstream = getapplicationcontext().openfileinput(filename); } if (inputstream != null) { inputstreamreader inputstreamreader = new inputstreamreader(inputstream); bufferedreader bufferedreader = new bufferedreader(inputstreamreader); string receivestring; stringbuilder stringbuilder = new stringbuilder(); while ( (receivestring = bufferedreader.readline()) != null ) { stringbuilder.append(receivestring).append(","); } inputstream.close(); ret = stringbuilder.tostring().split(","); inputstream.close(); } } catch (filenotfoundexception e) { } catch (ioexception e) { } return ret; }
i suppose have setpositivebutton click listener. start asynktask in listener desired input.
Comments
Post a Comment