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