Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在电子邮件主题中引用列表首选项_Android - Fatal编程技术网

Android 在电子邮件主题中引用列表首选项

Android 在电子邮件主题中引用列表首选项,android,Android,我不确定这是否可行,但我需要在列表首选项中选择的值显示在电子邮件主题中。这是应用程序提交功能代码的一部分 它的工作方式很好,但我需要用户选择在emailIntent.putExtra(android.content.Intent.EXTRA)主题行中显示的内容,以便在生成电子邮件时自动填充 我已经尝试了在这里和通过其他搜索可以找到的所有内容,但没有任何运气。如果您想要显示的值: private void submit() { SharedPreferences SP = Prefer

我不确定这是否可行,但我需要在列表首选项中选择的值显示在电子邮件主题中。这是应用程序提交功能代码的一部分

它的工作方式很好,但我需要用户选择在
emailIntent.putExtra(android.content.Intent.EXTRA)主题行中显示的内容,以便在生成电子邮件时自动填充


我已经尝试了在这里和通过其他搜索可以找到的所有内容,但没有任何运气。

如果您想要显示的值:

private void submit() 
{ 
    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    String listprefs = SP.getString("listprefs","1");              

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    String[] recipients = new String[]{""};
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, ); 
如果需要内部值,只需执行以下操作:

int i = listPreferenceObject.findIndexOfValue(listPreferenceObject.getValue());
String optionFromList = (String) listPreferenceObject.getEntries()[i];
...
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, optionFromList);
或者,您可以使用PreferenceManager对象检索值,就像您已经在做的那样。但是如果您已经在同一个活动中,我相信调用ListPreference会更容易

当然,我假设您正确初始化了listpreference对象。可能是:

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, listPreferenceObject.getValue());

这是您正在使用的
ListPreference
吗?我的意思是,preference条目显示您需要在
PreferenceActivity
中选择的单选项列表以及诸如此类的内容?您应该使用专有名称,以便我们确切地知道您在制作应用程序时使用的组件类型。是的,这是一个列表首选项at正在用于偏好活动。很抱歉,我对所有这些都不熟悉,我仍在学习所有术语以及它的作用。没问题,我只是在帮助您。请稍等,我将发布一些信息。:-)看看下面的代码是否对您有帮助。顺便说一句,记住点击绿色勾号接受答案。否则,人们帮不了你多少忙。我不得不把我所拥有的和你所发布的结合起来。我还必须把//TODO放在onCreate的末尾。非常感谢你的帮助
ListPreference listPreferenceObject = (ListPreference) this.findPreference("listprefs");