- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有设置类。我在里面使用偏好。在首选项中,我使用 AlertDialog
,其中包含 EditText
和 radioButton
。我想从我的设置 Activity 中获取编辑文本和单选按钮的值,但我在网上看到的所有内容都只是关于偏好或 AlertDialog
并且我不明白如果将它们组合在一起该怎么办.
我的 Settings.java:
public class Settings extends AppCompatActivity {
private RadioGroup radioGroup;
AlertDialog.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_setting, new MySettingsFragment())
.commit();
}
public static class MySettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.preference, rootKey);
}
@Override
public boolean onPreferenceTreeClick(Preference p){
final EditText input = new EditText(this.getContext());
if(p.getKey().equals("appointment type")){
return true;
}
if(p.getKey().equals("time frame")){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = requireActivity().getLayoutInflater();
builder.setView(inflater.inflate(R.layout.set_time, null)).
setPositiveButton(R.string.save_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
**Here i dont know how to take the value**
}
})
.setNegativeButton(R.string.cancel_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
我的 Preference.xml :
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="appointment type"
android:title="Set appointment types"
android:icon="@drawable/appoitment_type"
/>
<Preference
android:id="@+id/timeFrame"
android:key="time frame"
android:title="Allow change meeting"
android:summary="Time frame where clients can't change a meeting"
android:onClick = "popUpWindow"
android:icon="@drawable/no_meetings_changes"
/>
<Preference
android:id="@+id/remindTime"
android:key="remind time"
android:title="Meetings reminder"
android:summary="How much time to remind client before a meeting"
android:icon="@drawable/send_reminder" />
</PreferenceScreen>
我的 setTime.xml(对话框):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryLight">
<EditText
android:id="@+id/num_input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/default_num"
android:inputType="text" />
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/minutes_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minutes" />
<RadioButton
android:id="@+id/hours_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "@string/hours"/>
<RadioButton
android:id="@+id/days_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "@string/days"/>
<RadioButton
android:id="@+id/weeks_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "@string/weeks"/>
</RadioGroup>
</LinearLayout>
最佳答案
在 MySettingsFragment 的 OnPreferenceTreeClick
函数中:
@Override
public boolean onPreferenceTreeClick(Preference p){
final EditText input = new EditText(this.getContext());
if(p.getKey().equals("appointment type")){
return true;
}
if(p.getKey().equals("time frame")){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = requireActivity().getLayoutInflater();
View dialogView = inflater.inflate(R.layout.set_time, null) // add this line
builder.setView(dialogView).
setPositiveButton(R.string.save_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// take the value from selected radio button
RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radio_group);
int selectedId = radioGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
RadioButton radioButton = (RadioButton) findViewById(selectedId);
// get edittext value
EditText edittext = (EditText) dialogView.findViewById(R.id.num_input);
String edittextValue = edittext.getText().toString();
}
})
.setNegativeButton(R.string.cancel_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
关于java - 如何从首选项中的 AlertDialog 获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59399503/
有谁知道如何使 DIV 的行为方式使其始终尝试占用其最大空间(无论内容如何)? 例如,如果我有一个 max-height 的 DIV的 600px和一个 min-height的 200px ,我怎样才
考虑两个表表A和表B 表A |id|driver_id|vehicle_id|is_allowed|license_number|driver_name| 表B |id|driver_id|vehic
对于 ASP.NET 应用程序,自定义脏话删除器/替换器的最佳实践实现方法是什么? 如果这是一个数据表解决方案,是否有免费的资源来获取数据? (类似于找到可以导入到系统中进行拼写检查的公共(publi
有很多 jquery 工具提示插件。 我应该使用哪一个?为什么? 最佳答案 我们使用过qTip在我们的一个项目中,因为它符合我们的所有要求,开发和维护良好,附带优秀的文档和已经很漂亮的模板,并且还为我
我在Internet上四处张望,找不到相关信息。我的程序需要向PowerShell配置文件中编写一些PowerShell代码。如果没有配置文件,我的程序将创建一个。问题是应使用哪种编码来创建Power
在 D、int、uint 中使用 foreach 时,循环索引的首选类型是什么?或者只是通过省略类型自动实现? 最佳答案 一般来说,索引应该是size_t。与长度相同。如果您尝试使用 int 或 ui
这个问题在这里已经有了答案: Repeat each row of data.frame the number of times specified in a column (9 个回答) 2年前关闭
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我有一个看起来像这样的字符串: "Element 1 | Element 2| Element 3: element 4" 我想对冒号后面的源字符串部分进行子串(到源字符串的末尾),但如果没有冒号,那
我接受任何解释语言 Perl、Python、Bash 等。但我更喜欢 Perl,因为它是我想要学习的。我有一个时间戳列表,例如: 17:31:16 17:31:16 17:31:18 17:31:29
我想在后台运行程序。首选 C#我想把图标放在托盘里。在指定的时间同步文件夹(我知道如何同步文件夹)。如何在后台运行它并开始同步(例如凌晨 2 点)? 最佳答案 您需要考虑使用 windows sche
我有一个 onChange 事件处理程序,它的结构如下: (e) => (value => this.setState(prevState => ({ form: {
我想在windows 7中捕获删除操作。如果用户从计算机上删除了文件,我需要在文件被删除时存储一条记录,以及删除了哪个文件。 一般文件操作,不针对特定文件夹或软件。所以假设用户从 d:\testFol
是否有任何库或开源函数可以近似通过以不规则间隔获取的一些值来描述的线下的面积? 首选 Action Script,但 Java 也可以正常工作。 最佳答案 您可以使用as3mathlib数学图书馆。这
对于我的网络应用程序,我希望提供给用户的图像具有响应性。此外,我还想在图像标签中指定 width 和 height 属性,这样在移动连接速度较慢的情况下,就不会出现浏览器重排。 是否可以通过使用纯 H
在展示公司 Logo 时,我今天看到了一些新东西。 他们在 h1 标签上设置了高度和宽度以及 overflow:hidden 并在 h1 标签内的 a 标签上设置了负边距以防止文本显示。 代码是这样的
我使用 Lucene 库开发了一个索引和搜索应用程序。但是这个库在我的上下文中在自定义排名方面有一些限制,除了它的性能之外,我需要可扩展性和访问各种词频等。是否有任何强大的开源全文库可用? 最佳答案
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
这是一个关于当我需要在列表中查找对象实例时如何实现 equals 方法的问题,该实例的值是我在其成员中拥有的实例之一。 我有一个实现了 equals 的对象: class User { pri
我是一名优秀的程序员,十分优秀!