使用AlertDialog后,在子Activity中显示更新的textview

时间:2014-03-16 22:44:20

标签: android

我正在使用Tabhost,在第一个Tab(客户端)中,我有一个Parent Activity(包含一个listview),当我点击Listview中的一个项目时,一个子Activity将替换Parent一个,在同一个Tab中("客户"来自Tabhost),好的"不要睡着了:)" 在这个子Activity中,我有一个TextView和一个按钮,当单击该按钮时,AlertDialog会显示一个数字。

最后,"问题就在这里",当我输入一个数字并用AlertDialog确认时,我希望我的Textview立即显示数字,但它不会发生:&# 39;(

但是当我回到ParentActivity,然后再次返回到第一个孩子时,我发现了我更新的TextView,然后输入了Number ...

我希望,你们了解我(因为它太长了:))。 -编辑- 这是第一堂课:

public class Group_Clients extends ABCGroup{
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startChildActivity("Gestion_Clients", new Intent(this,Gestion_Clients.class));
}

}

这是第二类(包含Listview):

public class Gestion_Clients extends Activity{

BDD_Manage Bdd = new BDD_Manage(this);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab1_clients);

    ImageButton btn_addClient = (ImageButton) findViewById(R.id.client_add);
    ImageButton btn_subClient = (ImageButton) findViewById(R.id.client_delete);
    ImageButton btn_editClient = (ImageButton) findViewById(R.id.client_edit);
    ImageButton btn_chercher = (ImageButton) findViewById(R.id.client_search);
    ImageButton btn_actualiser = (ImageButton) findViewById(R.id.client_refresh);

    showListview();

    btn_addClient.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent edit = new Intent(getParent(), Clients_ajout.class);
            ABCGroup parentActivity = (ABCGroup)getParent();
            parentActivity.startChildActivity("Clients_ajout", edit);
        }
    });     

    btn_actualiser.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "Actualiser !", Toast.LENGTH_SHORT).show();
            onResume();
        }
    });

final ListView clientsList = (ListView)findViewById(R.id.listview_clients);
clientsList.setCacheColorHint(Color.TRANSPARENT);

clientsList.setOnItemClickListener(new OnItemClickListener() {
    @SuppressWarnings("deprecation")
    public void onItemClick(AdapterView<?> listView, View view, int position, long idClient) {
        Bdd.open();
        Bdd.putclientID((int) idClient);
        Bdd.close();

        Intent edit = new Intent(getParent(), Client_detaille.class);
        ABCGroup parentActivity = (ABCGroup)getParent();
        parentActivity.startChildActivity("Client_detaille", edit);
    }
});
}

这是第3类(包含按钮以及显示Alertdialog的位置):

public class Client_detaille extends Activity{

TextView tv_Nom, tv_colonnes, tv_infos, tv_avc, tv_datemodif, List_code, List_conduit, List_Examcode, List_Examconduit;
EditText S_code, S_conduit;
ImageButton addAvc, delAvc, addCode, delCode, addConduit, delConduit, addEXcode, delEXcode, delEXconduit, addEXconduit;
BDD_Manage bdd = new BDD_Manage(this);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.client_details);

    addAvc = (ImageButton) findViewById(R.id.add_avance);
    delAvc = (ImageButton) findViewById(R.id.del_avance);
    addCode = (ImageButton) findViewById(R.id.btn_plus01);
    delCode = (ImageButton) findViewById(R.id.btn_minus01);
    addConduit = (ImageButton) findViewById(R.id.btn_plus02);
    delConduit = (ImageButton) findViewById(R.id.btn_minus02);

    showInfos();

  //...... Config action of Button -Add Meeting- ......        
    addCode.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            alertBox(1, 1);
            onResume();
        }
    });
}
//~~~~~~~~~~~~Display Client Infos~~~~~~~~~~~~~~~~~~~~~~
@SuppressWarnings("deprecation")
public void showInfos(){
    String nom, prn, dn, nat, profs, adr, tel1, tel2, dateModif, avc="", payed="", notPayed="", scodes="", sconduits="", EXcodes="", EXconduits="";
    Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/fontastique.ttf");
    Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/small.ttf");

    tv_Nom = (TextView) findViewById(R.id.tv_name);
    tv_colonnes = (TextView) findViewById(R.id.text_left);
    tv_infos = (TextView) findViewById(R.id.text_right);
    tv_avc = (TextView) findViewById(R.id.tv_avance);
    tv_datemodif = (TextView) findViewById(R.id.text_datemodif);
    List_code = (TextView) findViewById(R.id.Scode001);
    List_conduit = (TextView) findViewById(R.id.Sconduit001);
    List_Examcode = (TextView) findViewById(R.id.Examcode001);
    List_Examconduit = (TextView) findViewById(R.id.ExamConduit001);

    bdd.open();
    Cursor cur = bdd.getdataFrom("Clients", bdd.getclientID());
    startManagingCursor(cur);
    cur.moveToFirst();

    nom   = cur.getString(1);      prn    = cur.getString(2);      dn         = cur.getString(3);    nat   = cur.getString(4);
    profs = cur.getString(5);      adr    = cur.getString(6);      tel1       = cur.getString(7);    tel2  = cur.getString(8);
    dateModif = cur.getString(9);  payed  = cur.getString(10);     notPayed   = cur.getString(11);   avc   = cur.getString(12);
    scodes= cur.getString(13);     sconduits = cur.getString(14);  EXcodes    = cur.getString(15);   EXconduits = cur.getString(16);

    tv_Nom.setTypeface(font1);
    tv_colonnes.setTypeface(font1);
    tv_infos.setTypeface(font1);
    tv_avc.setTypeface(font1);
    tv_datemodif.setTypeface(font2);
    List_code.setTypeface(font1);
    List_conduit.setTypeface(font1);
    List_Examcode.setTypeface(font1);
    List_Examconduit.setTypeface(font1);

    tv_Nom.setText(nom+" "+prn);
    //---------------------------
    tv_colonnes.setText(Html.fromHtml("Date naissance :<br>Nationalité :<br>Profession :<br>Adresse :<br>" +
            "Tel1 :<br>Tel2 :<br><font color='lime'>Payé : "+payed));
    //---------------------------
    tv_infos.setText(Html.fromHtml(dn+"<br>"+nat+"<br>"+profs+"<br>"+adr+
            "<br>"+tel1+"<br>"+tel2+"<br><font color='red'>A Payé : "+notPayed));
    //---------------------------
    if(avc!=null)
        tv_avc.setText(avc+" Dt");
    //---------------------------
    tv_datemodif.setText("modifié le: "+dateModif);
    //---------------------------
    if(scodes!=null && !scodes.equals(""))
        List_code.setText(scodes);
    //---------------------------
    if(sconduits!=null)
        List_conduit.setText(sconduits);
    //---------------------------
    if(EXcodes!=null)
        List_Examcode.setText(EXcodes);
    //---------------------------
    if(EXconduits!=null)
        List_Examconduit.setText(EXconduits);

    bdd.close();
}

2 个答案:

答案 0 :(得分:0)

static中创建一个MainActivity方法,该方法使用新的输入值设置TextVeiw,并按照以下方式调用此方法销毁CustomDialog:

public static void setUpdatedData(String value){
    textView.setText(value);
    textview.invalidate();
}

答案 1 :(得分:0)

我自己找到了解决方案:)

我只是在显示AlertDialog之前更新我的视图(所有textview(s)和其他...)。

LayoutInflater factory = LayoutInflater.from(getParent());
final View alertDialog = factory.inflate(R.layout.ajout_seance_code, null);
    AlertDialog.Builder adbx = new AlertDialog.Builder(getParent());
    adbx.setView(alertDialog);
    if(x==1){
        adbx.setTitle("Séance Code ++");
    }else{adbx.setTitle("Séance Conduit ++");}

    //On affecte un bouton "OK" à notre AlertDialog et on lui affecte un évènement
    adbx.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            BDD_Manage BdD = new BDD_Manage(getApplicationContext());
            String date, nbrH, prix, ligne="";
            EditText et_date, et_nbrH, et_prix;
            boolean res=true;
            int pr=0;
            BdD.open();
            .
            .etc
            .// and before showing the AlertDialog ( Alertdialog.show() ), i need here to update Textviex(s) values, so that way new datas are displayed instantly.
            showInfos();
            BdD.close();
        }
    });
    adbx.show();