当前位置: 首页 > news >正文

外包网站都有哪些关键词优化下拉管家

外包网站都有哪些,关键词优化下拉管家,wordpress翻页404,网络营销的基本方式我是Kotlin的新手#xff0c;我正在尝试为我的应用进行设置活动#xff0c;我希望该活动将其价值传递给其他活动。 我尝试了不同的代码#xff0c;但没有一个起作用#xff0c;我尝试制作一个共享的首选项文件#xff0c;但我不知道如何编写代码要清楚#xff0c;我想将字…我是Kotlin的新手我正在尝试为我的应用进行设置活动我希望该活动将其价值传递给其他活动。 我尝试了不同的代码但没有一个起作用我尝试制作一个共享的首选项文件但我不知道如何编写代码要清楚我想将字体类型从设置[main]活动传递到另一个活动但我不知道如何我的主要活动val preferences applicationContext.getSharedPreferences(MyPrefs, Context.MODE_PRIVATE)val prefEditor preferences.edit()val fonts arrayOf(Data1,Data2,Data3,Data4)val adapterCountry ArrayAdapter(this, android.R.layout.simple_list_item_1, fonts)val spinner findViewById(R.id.spinner) as Spinnerspinner.adapter adapterCountryspinner.setSelection(preferences.getInt(position, 0))spinner.onItemSelectedListener object : AdapterView.OnItemSelectedListener {override fun onItemSelected(parent: AdapterView, view: View, position: Int, id: Long) {spinner.setSelection(position)prefEditor.putInt(position, position)prefEditor.apply()val selecteditem parent.getItemAtPosition(position).toString()if (selecteditem Data1){}}override fun onNothingSelected(parent: AdapterView) {}}这是我的主要2活动class Main2Activity : AppCompatActivity() {internal lateinit var sh : SharedPreferencesoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main2)sh PreferenceManager.getDefaultSharedPreferences(this)}override fun onStart() {super.onStart()if (sh.getBoolean(positon, false)){when(sh.getInt(position, 0)){0-{t1.typeface Typeface.createFromAsset(assets,andlso.ttf)}1-{t1.typeface Typeface.createFromAsset(assets,frsspbl)}}}}我在这里找到了这个问题的解决方案在此处输入链接说明尝试将此回答改写为Kotlin。如果只是从那个活动到另一个活动而已链接在一起则可以考虑仅传递一个意图。 否则如果您确实需要在应用程序范围内使用首选项是个好方法developer.android.com/training/data-storage/shared-preferences因此基本上您想将Int中的数据(字体类型)从一个活动传递到另一个活动。 您可以使用SharedPrefenrences但在Android中不建议使用。我给您2个解决方案1.使用捆绑MainActivity.ktclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val fonts arrayOf(Data1,Data2,Data3,Data4)val adapterCountry ArrayAdapter(this, android.R.layout.simple_list_item_1, fonts)val spinner findViewById(R.id.spinner) as Spinnerspinner.adapter adapterCountryspinner.onItemSelectedListener object : AdapterView.OnItemSelectedListener {override fun onItemSelected(parent: AdapterView, view: View, position: Int, id: Long) {spinner.setSelection(position)val selecteditem parent.getItemAtPosition(position).toString()if (selecteditem Data1) {}// Start another activity with positionval intent Intent(thisMainActivity, Main2Activity::class.java)intent.putExtra(position, position);startActivity(intent)}override fun onNothingSelected(parent: AdapterView) {}}}}Main2Activity.ktclass Main2Activity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val position intent.getIntExtra(position, 0)}}2.使用SharedPreferencesMainActivity.ktclass MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val preferences PreferenceManager.getDefaultSharedPreferences(this)val fonts arrayOf(Data1,Data2,Data3,Data4)val adapterCountry ArrayAdapter(this, android.R.layout.simple_list_item_1, fonts)val spinner findViewById(R.id.spinner) as Spinnerspinner.adapter adapterCountryspinner.setSelection(preferences.getInt(position, 0))spinner.onItemSelectedListener object : AdapterView.OnItemSelectedListener {override fun onItemSelected(parent: AdapterView, view: View, position: Int, id: Long) {spinner.setSelection(position)val selecteditem parent.getItemAtPosition(position).toString()if (selecteditem Data1){}// Save position to prefs.preferences.edit().putInt(position, position).apply()}override fun onNothingSelected(parent: AdapterView) {}}}}Main2Activity.ktclass Main2Activity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)// Get position from prefs.val position PreferenceManager.getDefaultSharedPreferences(this).getInt(position, 0)}}您能告诉我如何在其他屏幕上获取数据吗 在这种情况下只需使用intent.getIntExtra(position, 0)或intent.getIntExtra(position1, 0)。Intent已经具有将信息从一个活动发送到另一个活动的功能。// in your first activity:val intent Intent(context, Main2Activity::class.java).putExtra(position, position)startActivity(intent)// in your second activity, you can fetch the extras like this:class Main2Activity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val position intent.getIntExtra(position, -1)}}我不建议使用共享首选项在屏幕之间传递事件因为如果您的应用在崩溃之前无法清理就可能陷入尴尬的状态从而无法清除其共享的偏好状态。它说上下文没有分类器
http://www.zqtcl.cn/news/908032/

相关文章:

  • 南京网站建设公司哪家好设计教程网站有哪些
  • 网页和网站做哪个好用吗陕西陕煤建设集团有限公司网站
  • 网站建设系统优势设计欣赏
  • 河北省网站建设东莞网站开发哪家好
  • php做学校网站免费苏州网站建设的公司
  • 网站做rss+wordpresswordpress动漫插件
  • wordpress更新网站内容公众号制作教程
  • 复兴区建设局网站怎么解压wordpress
  • 资源网站哪个好淄博网站设计
  • 网站建设林晓东网站数据库一般多大
  • 织梦网站后台默认登陆路径网站建设简介淄博
  • 重庆住房建设部网站东莞网站制作多少钱
  • 做胎儿羊水鉴定网站网站管理主要包括哪些内容
  • 公司网站建设应注意网店推广有哪些方法
  • 新网$网站优化企业资源管理软件
  • 甘肃营销型网站制作网页设计流程的图片
  • 厦门成交型网站建设公司今科云平台网站建设
  • 网站推广效果怎样学电商赚钱
  • 企业网站的一般要素包括哪些公司网站建设是什么费用
  • 网站收录说明长沙知名的营销公司
  • 网站开发 业务流程图天津网站排名方案
  • 风雨同舟网站建设小说网站如何做书源
  • h5手机网站建设哪家好广州有什么好玩的地方和风景好
  • 北京哪个网站建设最好怀化网站建设公司
  • 做类似猪八戒网的网站注册一个商标多少钱
  • 怎么提高网站访问速度wordpress怎么备份按在
  • 淘宝网站是谁做的好处wordpress商业授权
  • 淘宝客网站怎么批量采集淘宝商品方维采集淘宝数据思路珠宝类网站建设
  • 重庆网站关键字优化雅布设计中国分公司在哪里
  • 山西做网站费用温州做网站制作