[英]i want to show data in **only one** textview when i clickd on buttons...both buttons have different data
firstacivity第一活动
public void onClick(View v) {
switch (v.getId()){
case R.id.button :
Intent intent1 = new Intent(this, Main3Activity.class);
intent1.putExtra("value1", strsongdetails);
startActivity(intent1);
break;
case R.id.button3:
Intent intent2 = new Intent(this, Main3Activity.class);
intent2.putExtra("value2", NameOfTheString);
startActivity(intent2);
break;
default:
break;
}
}
*secondactivity * *第二活动*
TextView textView3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
textView3=(TextView)findViewById(R.id.textView3);
//i want to show data in only one textview when i clickd on buttons...both buttons have different data //i create 2 activities In first thereare two buttons and in third there is textview which i wanted to connet a string & when i clickd on button they want to see the data from text view //当我点击按钮时,我只想在一个文本视图中显示数据......两个按钮都有不同的数据//我创建了2个活动首先有两个按钮,第三个是我想连接字符串的文本视图&何时我点击了他们想要从文本视图中查看数据的按钮
Hello if i have understand your question you want to press a button, send the message to the second activity and display it to a textview.您好,如果我理解您的问题,您想按下一个按钮,将消息发送到第二个活动并将其显示到文本视图中。 Add this code after textView3=(TextView)findViewById(R.id.textView3);在 textView3=(TextView)findViewById(R.id.textView3); 之后添加此代码;
String message="";
if(getIntent().hasExtra("value1")){
message = getIntent().getStringExtra("value1");
}else if(getIntent().hasExtra("value2")){
message = getIntent().getStringExtra("value2");
}else{
// no message passed to activity
}
textView3.setText(message);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.