简体   繁体   English

当我点击按钮时,我想在 **only one** textview 中显示数据......两个按钮都有不同的数据

[英]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.

相关问题 我在一个布局中有三个按钮,我想显示不同的视图 - i have three buttons in a one layout and i want to show diffrent view 我有两个按钮,我创建XML以使按钮圆。但我想给两个按钮提供不同的颜色 - I have two button for which i create the XML to make buttons round.But I want to give the different color to both button 文字和按钮被覆盖...我希望按钮固定在textview的底部 - text and buttons gets overlayed…i want the buttons fixed at the bottom of the textview 我有一个RSS供稿,想将其数据显示到textview中 - i have a rss feed and want to display its data into textview 如何使用不同的按钮在列表视图中显示数据 - how to show data in listviews with different buttons 我在测试中有5个选择。 我有一个csv数据库。 当我按下其中一个按钮时,我希望按钮上的“文本”更改为下一个标题 - I have 5 choices in a test. I have a csv database. When I press on one of the buttons, I want the Text on the button to change to the next header 我想水平放置五个图像按钮,但是在某些设备上我只能得到四个按钮 - I want to place five imagebuttons horizontally, but when I do I only get 4 buttons in some devices 为什么,两个单选按钮都被选中了? 我要单选 - Why, Both radio buttons selected? i want single selection 我在onClick的按钮上有一个开关盒,但两个活动都已开始 - I have a switchcase for my buttons in onClick but both activities are starting 两个单选按钮可以选择一次,但我只想选择一个 - Two radio buttons can be selected once though i want to select only one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM