[英]use EditText to change TextView value on another activity (backoffice)
I am wanting to create an Admin backoffice for my app, where I can update text in other activities that are set as TextView(should they be EditText)? 我想为我的应用程序创建一个管理后台,我可以在其中更新设置为TextView(应为EditText)的其他活动中的文本吗? I have an EditText box in my Admin activity, and have set a button that "should" initialize the copying of current contents in EditText and save it to a variable "flowSales", I than try to grab the variable "flowSales" in my customer activity and .setText to my TextView. 我在Admin活动中有一个EditText框,并设置了一个按钮,“应该”初始化EditText中当前内容的复制并将其保存到变量“ flowSales”,而不是尝试在客户中获取变量“ flowSales”活动和.setText到我的TextView。 Any help would be appreciated even if it's a simple, you are doing it wrong. 即使它很简单,您做错了任何帮助,也将不胜感激。
I am able to find variable "flowSales" in my second activity, at this time my "var flowSales = Editable" returns no companion for Editable. 我可以在第二个活动中找到变量“ flowSales”,这时我的“ var flowSales = Editable”不返回Editable的伴随对象。
adminPage.kt (back office) editMeFs is the EditText box, and flowSales is a variable I created so I can pull it to second activity adminPage.kt(后台)editMeFs是EditText框,flowSales是我创建的变量,因此可以将其拉至第二个活动
var flowSales = Editable
class adminPage : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_admin_page)
upDate.setOnClickListener{
flowSales = editMeFs.text
}
}
}
activity2.kt (user page) flowersales is the TextView to be updated activity2.kt(用户页面)flowersales是要更新的TextView
class Activity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_activity2)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
flowersales.setText(flowSales)
}
}
So right now with var flowSales = Editable
I am unable to run the app, returning error 所以现在使用var flowSales = Editable
我无法运行该应用程序,返回错误
"\adminPage.kt: (9, 17): Classifier 'Editable' does not have a companion object, and thus must be initialized here",
if i set "= null" or "= 0"
I can run my app and click the button on admin page, however when i go to the Activity 2 it has not updated the text that i had put into EditText. 我可以运行我的应用程序,然后单击管理页面上的按钮,但是当我转到活动2时,它没有更新我放入EditText中的文本。
Firstly, always class name start with upper case. 首先,类名始终以大写开头。 This is the truth; 这是事实。
class AdminPage: AppCompatActivity()
If we come to your problem, you can solve this way; 如果我们解决您的问题,您可以采用这种方式解决;
lateinit var flowSales: String
class AdminPage : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_admin_page)
upDate.setOnClickListener{
flowSales = editMeFs.text.toString()
}
}
}
var flowSales: String = ""
class adminPage : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_admin_page)
//do this function when button is clicked
upDate.setOnClickListener{
//edit the the variable to fit what's in editText
flowSales = editMeFs.text.toString()
}
}
}
user activity 用户活动
class Activity2 : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_activity2)
setSupportActionBar(toolbar)
fab.setOnClickListener { view ->
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
}
//call variable from admin page and set as flowersales text
flowersales.text = flowSales
}
}
this works 这有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.