简体   繁体   English

创建许多TextView并给它们提供ID之后,我试图用他们的信息打开一个活动。 我怎么做?

[英]After creating many TextViews and giving them IDs, I am trying to open an activity with their information. How do I do that?

So I can successfully create an android Text View using java and set it a value and an ID. 因此,我可以使用java成功创建一个android文本视图,并将其设置为值和ID。 But my problem is that after I create them and gave them values and id, I have no control over them. 但是我的问题是,在创建它们并为它们提供值和ID之后,我无法控制它们。 After clicking on them, I want the new page to have the data that was stored in that Text View. 单击它们之后,我希望新页面具有该文本视图中存储的数据。

Here is how I created and set value and ID to my Text Views: 这是我创建和设置文本视图的值和ID的方法:

                             textView = new TextView(SellActivity.this);

                            // put the data in the text view
                            textView.setText(data);


                            // give it an id
                            textView.setId(Integer.parseInt(getStrID));


                            //place it nicely under one another
                            textView.setPadding(0, 50, 0, 0);

                            // if clicked any of the textviews, open the offer page
                            textView.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    //setGetStrID(getStrID);
                                    Intent intent = new Intent(SellActivity.this, OfferActivity.class);
                                    startActivity(intent);
                                }
                            });

                            // add the text view to our layout
                            linearLayout.addView(textView);

You can put the data in the intent when you are opening a new activity 您可以在打开新活动时将数据放入意图中

textView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                //setGetStrID(getStrID);
                                Intent intent = new Intent(SellActivity.this, OfferActivity.class);
                                intent.putExtra("mydata", textView.getText());
                                startActivity(intent);
                            }
                        });

In the oncreate of OfferActivity receive this data as string 在OfferActivity的oncreate中,以字符串形式接收此数据

String mydata = intent.getStringExtra("mydata");

You just have to pass the data to the new intent, 您只需要将数据传递给新的意图,

textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
             Intent intent = new Intent(SellActivity.this, OfferActivity.class);
             intent.putExtra("TextViewContent", textView.getText());
             startActivity(intent);
        }
});

Then in onCreate function of OfferActivity.java , 然后在OfferActivity.java onCreate函数中,

String s = getIntent().getStringExtra("TextViewContent");

Now the string s will contain the value of your textView. 现在,字符串s将包含textView的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 看不到 javadoc 信息。 我如何解决它? - Can't see javadoc information. How do I fix it? 如何通过检索上传到Firebase数据库或存储的Image,TextViews来设置活动的ImageView,TextViews? - How do i set ImageView,TextViews of an activity by retriving Image,TextViews that i uploaded to firebase database or storage? 如何在Android中注册81个textviews? - how Do i register 81 textviews in android? 我如何将两个textview对齐在可绘制对象的顶部,以防止它们彼此堆积 - How do i align both textviews on top of the drawable preventing them to pile up on eachother 如何保存一些textview并从另一个类加载它们? - How do I save some textviews and load them from another class? 启动新应用程序后如何在不创建新活动的情况下返回相同的活动 - How do I come back to the same activity after launching a new app without creating a new activity 如何在Android的第二个活动中显示信息 - How do I display information in my second activity in Android 我试图找到元音然后添加它们,但是我这样做对吗? - I am trying to find vowels then add them, but did i do this right? 我无法做到去详细的活动 - I am unable to do to go to the detailed Activity 如何在 listView 的 1 行中显示 2 个 textView? - How do i make 2 textViews apear in 1 row in listView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM