2017-04-25 20 views
0

你好,我正在開發一個應用程序android,我有一個文本視圖通過web服務檢索數據的問題,數據檢索出現,但侵犯了頁面的其他文本視圖,這是我的代碼從我的XML頁面:androit文本視圖Mysql

<?xml version="1.0" encoding="utf-8"?> 

<TextView 
    android:id="@+id/tvd" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="Détail de l'établissement" 
    android:textSize="20dp" 
    android:textStyle="bold"/> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="42dp" 
    android:text="Libelle :" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:layout_below="@+id/tvd" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<TextView 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="64dp" 
    android:text="Code postal :" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:layout_below="@+id/textView3" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<TextView 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="64dp" 
    android:text="Ville :" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:layout_below="@+id/textView4" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

<TextView 
    android:id="@+id/tvl" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/textView3" 
    android:layout_alignParentEnd="true" 
    android:hint="libelle" 
    android:textSize="20dp" 
    /> 

<TextView 
    android:id="@+id/tvcp" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/tvl" 
    android:layout_alignStart="@+id/tvl" 
    android:layout_alignTop="@+id/textView4" 
    android:hint="Code postal" 
    android:textSize="20dp" /> 

<TextView 
    android:id="@+id/tvv" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/tvcp" 
    android:layout_alignStart="@+id/tvcp" 
    android:layout_alignTop="@+id/textView5" 
    android:hint="Ville" 
    android:textSize="20dp" /> 

<Button 
    android:id="@+id/btnMa" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:text="Matériel numérique associé" 
    android:textSize="20dp" 
    android:textStyle="bold|italic" 
    /> 

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:layout_below="@+id/textView5" 
    android:layout_marginTop="39dp" 
    android:text="Présentation" /> 

<TextView 
    android:id="@+id/tvp" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@+id/textView" 
    android:layout_alignLeft="@+id/tvv" 
    android:layout_alignStart="@+id/tvv" 
    android:hint="Presentation" 
    android:textSize="20dp" /> 

然後我的代碼,說還是去數據:

public class DetailEtab extends Activity { 
    private TextView tv; 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.etabdetail); 

     tv = (TextView) findViewById(R.id.tvl); 
     tv.setText(search_ville.etabSELECT.getLibelle()); 

     tv = (TextView) findViewById(R.id.tvcp); 
     tv.setText(search_ville.etabSELECT.getCp()); 

     tv = (TextView) findViewById(R.id.tvv); 
     tv.setText(search_ville.etabSELECT.getVille()); 

     tv = (TextView) findViewById(R.id.tvp); 
     tv.setText(search_ville.etabSELECT.getPresentation()); 


     Button btnSa = (Button) findViewById(R.id.btnMa); 
     btnSa.setOnClickListener(new Button.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class); 
       startActivity(intent); 
       Log.i("ETAB", "servcies associes"); 
       Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT); 
       toast.show(); 
      } 
     }); 
    } 
} 

如果有人能告訴我爲什麼它,多虧

[截圖] [1] [1]:https://i.stack.imgur.com/ImHxk.png

+0

你可以添加一個屏幕截圖,請? – fightingCoder

+0

是的,我添加了它。 –

+0

你也可以發佈完整的XML文件? – fightingCoder

回答

0

你必須與你的佈局問題。我建議你將每行都包裝到單獨的LinearLayout中,然後使用LinearLayout來包裝所有新的LinearLayout。同樣由於長文本,將父代LinearLayout封裝到Scroll中會更好。 注意:這是被寫入文本框,只顯示主要的想法,並可能包含錯誤 像這樣的東西里面只是例子:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
<LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/tvd" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Détail de l'établissement" 
    android:textSize="20dp" 
    android:textStyle="bold"/> 
<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

<TextView 
    android:id="@+id/textView3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="42dp" 
    android:text="Libelle :" 
    android:textSize="20dp" 
    android:textStyle="bold" 
/> 

<TextView 
    android:id="@+id/tvl" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="libelle" 
    android:textSize="20dp" 
    /> 
</LinearLayout> 

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/textView4" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="64dp" 
    android:text="Code postal :" 
    android:textSize="20dp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/tvcp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="Code postal" 
    android:textSize="20dp" /> 
</LinearLayout> 

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/textView5" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="64dp" 
    android:text="Ville :" 
    android:textSize="20dp" 
    android:textStyle="bold" /> 
<TextView 
    android:id="@+id/tvv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="Ville" 
    android:textSize="20dp" />  

</LinearLayout> 

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:layout_marginTop="39dp" 
    android:text="Présentation" /> 

<TextView 
    android:id="@+id/tvp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:hint="Presentation" 
    android:textSize="20dp" /> 
</LinearLayout> 

<Button 
    android:id="@+id/btnMa" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Matériel numérique associé" 
    android:textSize="20dp" 
    android:textStyle="bold|italic" 
    /> 


</LinearLayout> 
</ScrollView> 
+0

merci c'estdéjamieux,j'ai juste a bien tout mettre en face maintenat。 –

0

您將電視到多個不同的TextViews,然後你到指定多個值你分配給它的最後一個TextView。

0
public class DetailEtab extends Activity { 
    private TextView tv,tv1,tv2,tv3; 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.etabdetail); 

     tv = (TextView) findViewById(R.id.tvl); 
     tv.setText(search_ville.etabSELECT.getLibelle()); 

     tv1 = (TextView) findViewById(R.id.tvcp); 
     tv1.setText(search_ville.etabSELECT.getCp()); 

     tv2 = (TextView) findViewById(R.id.tvv); 
     tv2.setText(search_ville.etabSELECT.getVille()); 

     tv3 = (TextView) findViewById(R.id.tvp); 
     tv3.setText(search_ville.etabSELECT.getPresentation()); 


     Button btnSa = (Button) findViewById(R.id.btnMa); 
     btnSa.setOnClickListener(new Button.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class); 
       startActivity(intent); 
       Log.i("ETAB", "servcies associes"); 
       Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT); 
       toast.show(); 
      } 
     }); 
    } 
} 
+0

總是相同且沒有區別。 –

0

試試這個佈局:

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

    <TextView 
     android:id="@+id/tvd" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:text="Détail de l'établissement" 
     android:textSize="20dp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/tvd" 
     android:layout_marginTop="42dp" 
     android:text="Libelle :" 
     android:textSize="20dp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView3" 
     android:layout_marginTop="64dp" 
     android:text="Code postal :" 
     android:textSize="20dp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/textView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView4" 
     android:layout_marginTop="64dp" 
     android:text="Ville :" 
     android:textSize="20dp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/tvl" 
     android:layout_width="200dp" 
     android:layout_height="80dp" 
     android:layout_alignParentEnd="true" 
     android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf" 
     android:layout_alignTop="@+id/textView3" 
     android:hint="libelle" 
     android:textSize="20dp" 
    /> 

    <TextView 
     android:id="@+id/tvcp" 
     android:layout_width="200dp" 
     android:layout_height="80dp" 
     android:layout_alignLeft="@+id/tvl" 
     android:layout_alignStart="@+id/tvl" 
     android:layout_alignTop="@+id/textView4" 
     android:hint="Code postal" 
     android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf" 

     android:textSize="20dp"/> 

    <TextView 
     android:id="@+id/tvv" 
     android:layout_width="200dp" 
     android:layout_height="80dp" 
     android:layout_alignLeft="@+id/tvcp" 
     android:layout_alignStart="@+id/tvcp" 
     android:layout_alignTop="@+id/textView5" 
     android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf" 

     android:hint="Ville" 
     android:textSize="20dp"/> 

    <Button 
     android:id="@+id/btnMa" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:text="Matériel numérique associé" 
     android:textSize="20dp" 
     android:textStyle="bold|italic" 
    /> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/textView5" 
     android:layout_marginTop="39dp" 
     android:text="Présentation" 
     android:textSize="20dp" 
     android:textStyle="bold"/> 

    <TextView 
     android:id="@+id/tvp" 
     android:layout_width="200dp" 
     android:layout_height="80dp" 
     android:layout_below="@+id/tvv" 
     android:layout_toRightOf="@id/textView" 
     android:layout_alignLeft="@+id/tvv" 
     android:layout_alignStart="@+id/tvv" 
     android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf" 
     android:hint="Presentation" 
     android:textSize="20dp"/> 
</RelativeLayout>