c# - 如何从从以前的活动中获取内容的数组从列表转换为字符串
问题描述
我试图在单击后转换列表中的特定项目,它转换为字符串,然后将该信息发送回 MainActivity。将信息转换为字符串时遇到问题。
namespace GPS2
{
[Activity(Label = "@string/GPSHistory")]
public class GPSHistory : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
// Draw controls
// SetContentView(Resource.Layout.GPSHistoryLayout);
var strGPSAnswer = Intent.Extras.GetStringArrayList("Answer") ?? new string[0];
ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, strGPSAnswer);
ListView.TextFilterEnabled = true;
ListView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args)
{
//Confirmation that it works.
Toast.MakeText(Application, ((TextView)args.View).Text, ToastLength.Short).Show();
//Prepare string and send back to first page.
var i = new Intent(this, typeof(MainActivity));
i.PutExtra("string", strGPSAnswer);
StartActivity(i);
};
}
}
}
解决方案
根据 Android Intent 文档 intent extras,
putStringArrayListExtra
名称应该是:
向意图添加扩展数据。名称必须包含包前缀,例如应用程序 com.android.contacts 将使用类似“com.android.contacts.ShowAll”的名称
在您的代码中,看起来“答案”是不包括包前缀的键。
我本可以在评论中添加这个,但没有足够的积分。
推荐阅读
- javascript - 使用 React 和 Enzyme 测试 Javascript 类属性
- python - 来人解释一下为什么这段代码对我不起作用?
- c# - Moq 通用存储库模式
- c# - ac# 控制台应用程序可以在 Windows 控件上获取反射信息吗?
- c# - 中继器不创建子控件
- android - 带有大 msg.obj 的处理程序可以抛出 TransactionTooLargeException 吗?
- azure-data-factory - 在 ADF 管道中使用 Teradata 作为源调整批量读取大小
- linux - 如何使用 vim 来检查某些可执行文件的 -h 参数或手册?
- angular - 在 Angular 中,当组件不是父/子时,如何将值从一个组件传递到另一个组件?
- python - Python pandas数据框检查一列的值是否在另一个列表中