Textview
(tt
) не отображает текст, заданный setText()
. Я не могу видеть вывод в TextView
. Я попытался использовать Toast
и setText()
, но в обоих случаях я получаю пустой вывод. Почему я получаю этот пустой вывод?TextView пуст при установке с помощью setText()
package com.divik.ds;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
EditText ed1,ed2,ed3;
String x,y,z,xx;
TextView tt;
Button btn;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText) findViewById(R.id.editText1);
ed2=(EditText) findViewById(R.id.editText2);
ed3=(EditText) findViewById(R.id.editText3);
tt= (TextView) findViewById(R.id.textView4);
btn=(Button) findViewById(R.id.button1);
try{
x=(ed1.getText().toString());
y=(ed2.getText().toString());
z=(ed3.getText().toString());
xx=x+""+y+""+z;
btn.setOnClickListener(this);
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public void onClick(View v) {
try{
tt.setText(xx);
}
catch(Exception e)
{
e.printStackTrace();
}
Toast.makeText(this,xx,Toast.LENGTH_LONG).show();
}}
Код xml. Я использовал 3 EditText
с, 4 TextView
с и 1 Button
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Date"
android:textSize="30dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter month"
android:textSize="30dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter year"
android:textSize="30dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textSize="30dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Дайте мне знать, если этот код не работает. И если его работа затем отметит этот ответ, как принято. –
Да, это работает .thnx – RisingSun
@RisingSun Удостоверьтесь, что вы понимаете *** почему *** он работает, потому что это принесет вам больше пользы в будущем, чем просто его работа * сейчас *. – codeMagic