按钮未显示

时间:2011-06-21 08:12:42

标签: android xml button android-layout textview

我尝试显示我的textview和按钮,但它没有显示按钮(但textview是)

我没有错误,但按钮丢失了!

这是班级:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v("", "Welcome in  FirstTab");
    setContentView(R.layout.firsttab);

    // Get the app's shared preferences
    app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
    //authsettor = app_preferences.getInt("authsettor", 1);
    login = app_preferences.getString("login", "login");login = login.replaceAll(" ", "");login = login.replaceAll("    ", "");
    pass = app_preferences.getString("pass", "pass");pass = pass.replaceAll(" ", "");pass = pass.replaceAll("   ", "");
    authsettor = app_preferences.getInt("authsettor", 1);

    //int i = 1; 
    //if (i==1) { // pour forcer l'ouverture de la boite de dialogue
    if (authsettor==1) {
        //si l'authsettor =1, il doit être affiché :
        DialogBoxAuth dialog = new DialogBoxAuth(this);
        dialog.setTitle("Authentification requise");
        dialog.show();

        dialog.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                loadText(); // ne lancera l'affichage du texte que quand on aura ferme la boite d dialogue
            }
        });

        final Button buttonJour = (Button) findViewById(R.id.accessGrapheJour);
        buttonJour.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.v("", "bouton cliqué 1");
            }
        });

        final Button buttonMois = (Button) findViewById(R.id.accessGrapheMois);
        buttonMois.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.v("", "bouton cliqué 2");
            }
        });

        final Button buttonAn = (Button) findViewById(R.id.accessGrapheAn);
        buttonAn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.v("", "bouton cliqué 3");
            }
        });
    }
    else {loadText();}
}



public void loadText() {
    ProgressDialog progressDialog = ProgressDialog.show(FirstTab.this, "", "Veuillez patienter...", true);


    /** TextView-> AFFICHER DONNEES RECUES */
    final TextView textView = (TextView) findViewById(R.id.texte_firsttab);
    textView.setText(Html.fromHtml("<br /><b>Détails du compteur</b><br />" +
            "  Numéro de Série<br />"
            ));

    progressDialog.dismiss();// arrête le dialogbox pour patienter si connexion lente

    if(listAlertsInfos.get(0).getAlertAuth().contentEquals("0") && authsettor == 0 ){
        Toast toast = Toast.makeText(this, "Erreur de login et/ou mot de passe", 3000);toast.show();
    }
}

}

我已经制作了这个XML:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView android:id="@+id/texte_firsttab"   
    android:layout_height="wrap_content"   
    android:layout_width="wrap_content"/>

</LinearLayout>

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <Button android:id="@+id/accessGrapheJour"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="test1"
    android:onClick="selfDestruct" />

   <Button android:id="@+id/accessGrapheMois"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="test2"
    android:onClick="selfDestruct" />

    <Button android:id="@+id/accessGrapheAn"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="test3"
    android:onClick="selfDestruct" />

</LinearLayout>

</LinearLayout>

如果您知道我如何解决它,请告诉我。

感谢!!!!!

2 个答案:

答案 0 :(得分:1)

你应该将内部 LinearLayout 的高度设为 wrap_content

答案 1 :(得分:1)

在线性布局中使用wrap_content ...您还可以使用android:weight来校正每个线性布局的空间...在每个线性布局中将其设置为1,它们将屏幕划分为半个