2014-11-14 8 views
1

2가 TextView인데 그 중 하나에 텍스트가 표시되지 않습니다. 내가 거기에있는 LogCat에서 볼 수 있지만 그것은 표시되지 않습니다. 문제가 내 xml 파일에 있다고 확신하지만 정확히 무엇을 모르겠습니다. 또한 나는 이것과 같은 많은 포스트를 여기에서 보았다. 그리고 나는 그들과 다른 것을 시험해 보았다. 그러나 non는 나를 도와 줬다. 여기 레이아웃TextView에 텍스트가 표시되지 않습니다

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

<LinearLayout 
    android:layout_width="320dp" 
    android:layout_height="wrap_content" 
    android:minHeight="50dp" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="300dp" 
     android:layout_height="0dp" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:layout_weight="10.18" 
     android:background="@drawable/buttons" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="280dp" 
      android:layout_height="wrap_content" 
      android:paddingBottom="10dp" 
      android:paddingLeft="5dp" 
      android:paddingTop="5dp" 
      android:text="" /> 

     <TextView 
      android:id="@+id/text" 
      android:layout_width="280dp" 
      android:layout_height="wrap_content" 
      android:paddingBottom="10dp" 
      android:paddingLeft="5dp" 
      android:paddingTop="5dp" 
      android:layout_marginTop="10dp" 
      android:text="" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="300dp" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="5dp" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/pressMe" 
      android:layout_width="300dp" 
      android:layout_height="40dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/bg_button" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="@string/PressMe" /> 

     <Button 
      android:id="@+id/dontPress" 
      android:layout_width="300dp" 
      android:layout_height="40dp" 
      android:layout_marginTop="5dp" 
      android:layout_marginBottom="5dp" 
      android:background="@drawable/bg_button" 
      android:gravity="center" 
      android:padding="4dp" 
      android:text="@string/DontPressMe" /> 
    </LinearLayout> 

</LinearLayout> 

</ScrollView> 

문제가 TextView 내가 getExtra

intent.putExtra("text", stocks[position].text); 
intent.putExtra("name", stocks[position].name); 

하고 그래서

Bundle b = getIntent().getExtras(); 
    if (b != null) { 
     name = b.getString("name"); 
     textView.setText(name+""); 
     text = b.getString("text"); 
     textView.setText(text+""); 

putExtra 통해 다른 활동에서 그들을 얻고 또한 "@+id/name"

입니다은 있지만 name가 없습니다. 첫 번째 활동에는 둘 다 있습니다.

textView = (TextView) findViewById(R.id.name); 
    textView = (TextView) findViewById(R.id.text); 
+0

활동 코드를 넣을 수 있습니까? –

+0

TEXT를 XML로만 설정해보세요. 표시 되나요? –

+0

지연에 대한 사과 .. 내 PC 충돌. 예, 텍스트를 XML에 넣으면 둘 다 볼 수 있습니다. 다른 하나는 있어야합니다. – Goro

답변

3

이 레이아웃

에는 문제가 없지만 문제에 코드를 작성하면 oncreate 메소드에서 textView를 모두 찾아야합니다. 두 가지 모두 찾았지만 문제는 동일한 텍스트 참조를 사용하여 텍스트를 설정할 때

두 텍스트보기에 대해 동일한 참조를 사용한다는 것입니다. 이런 식으로 바꿔.

textView = (TextView) findViewById(R.id.name); 
textView = (TextView) findViewById(R.id.text); 
textView.setText(name+""); 
textView.setText(text+""); 

두 개의 텍스트 뷰를 유지하고이 작업을 수행 :이 코드가 도움이 될 수

TextView txtName = (TextView)findviewbyid(R.id.name); 
TextView txtText = (TextView)findviewbyid(R.id.text); 

    Bundle b = getIntent().getExtras(); 
     if (b != null) { 
      name = b.getString("name"); 
      //change here txtName.setText(name+""); 
      text = b.getString("text"); 
      //change here txtText.setText(text+""); 
} 
+0

가 작동되고 이름이 또한있다. 그러나이 경우 텍스트 뷰 하나만 표시되지 않는 이유는 무엇입니까? – Goro

2
android:paddingBottom="10dp" 

당신이있는 이유는 무엇입니까? 아래 코드를 사용해보십시오

android:layout_marginBottom="10dp" 
+0

이유는'marginBottom' 대신'paddingBottom'의 사용해야합니까? 나는 내용과 뷰 사이의 공간을 원하기 때문에 나는 패딩을 사용 .. 텍스트가 정말 존재하지만 기회는 공간이 충분하지 않습니다 표시되지 않습니다, 그래서 만약 – Goro

+0

패딩은, 레이아웃 내부에 간다. 여백이 레이아웃 외부로 이동합니다. 당신이 그것을 결코 사용해서는 안됩니다. –

+0

예, 나는 당신이 당신의 대답에 무슨 뜻인지 이제 이해합니다. 고맙습니다. – Goro

1

:

을 제거하거나 그것을 변경해보십시오

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

    <LinearLayout 
     android:layout_width="320dp" 
     android:layout_height="wrap_content" 
     android:minHeight="50dp" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="300dp" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="10dp" 
      android:background="@drawable/chat_add_contact" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/name" 
       android:layout_width="280dp" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:paddingTop="5dp" 
       android:text="dsgdsfgdfhdgfhfjhgfj" /> 

      <TextView 
       android:id="@+id/text" 
       android:layout_width="280dp" 
       android:layout_height="wrap_content" 
       android:paddingBottom="10dp" 
       android:paddingLeft="5dp" 
       android:paddingTop="10dp" 
       android:layout_marginTop="10dp" 
       android:text="sfgdfhgfjgfjhgjhg" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="300dp" 
      android:layout_height="fill_parent" 
      android:layout_marginLeft="10dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

      <Button 
       android:id="@+id/pressMe" 
       android:layout_width="300dp" 
       android:layout_height="40dp" 
       android:layout_marginTop="5dp" 
       android:background="@drawable/ic_launcher" 
       android:gravity="center" 
       android:padding="4dp" 
       android:text="PressMe" /> 

      <Button 
       android:id="@+id/dontPress" 
       android:layout_width="300dp" 
       android:layout_height="40dp" 
       android:layout_marginTop="5dp" 
       android:layout_marginBottom="5dp" 
       android:background="@drawable/ic_launcher" 
       android:gravity="center" 
       android:padding="4dp" 
       android:text="DontPressMe" /> 
     </LinearLayout> 

    </LinearLayout> 

</ScrollView> 
1
TextView txtCont = (TextView) findViewById(R.id.name); 
+0

네, 둘 다 가지고있다. 내 질문에 업데이트 이와 같이 – Goro

1

변화,

Bundle b = getIntent().getExtras(); 
    if (b != null) { 
     name = b.getString("name"); 
     ((TextView)findviewbyid(R.id.name)).setText(name+""); 
     text = b.getString("text"); 
     ((TextView)findviewbyid(R.id.text)).setText(text+""); 
2

이 사용 같은 텍스트 뷰 객체의 텍스트를 덮어 쓰는

TextView textview1, textview2; 
textView1 = (TextView) findViewById(R.id.name); 
textView2 = (TextView) findViewById(R.id.text); 
textView1.setText("name"); 
textView2.setText("description"); 

희망 사항 .

+1

는 답변 주셔서 감사합니다. 나는 이것이 텍스트 덮어 쓰기라는 것을 몰랐다. – Goro

관련 문제