android - How to make a custom Preference layout launch a Dialog Fragment and react to Button?
问题描述
I have made the custom layout for the preference layout with one button and the text view .How to open the dialog fragment when user click on the text view field and also interact the button on the field ?
This is What i want , when the toggle button is off .The person cant open the dialog fragment .Once the toggle button is enabled the dialog fragment will get active and user can edit the value and that will get update in summary.
Preference.xml
<com.example.app.Utils.CustomIPPreference
android:key="@string/pref_manual_IpKey"
android:title="Set Device Ip manually"
android:summary="@string/default_ip" />
CustomIPPreference.java
public class CustomIPPreference extends Preference {
public CustomIPPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
setLayoutResource(R.layout.custom_ip_device_select);
}
@Override
protected void onBindView(View view) {
LinearLayout layout = view.findViewById(R.id.ManualIPBOX_layout);
SwitchCompat switchCompat = view.findViewById(R.id.manualIpToggle);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtils.e("pref_manual_IpKey");
CustomIpDialog customIpDialog = new CustomIpDialog();
customIpDialog.show(getFragmentManager(), "Frag"); //getFragmentManager not found error
}
});
switchCompat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtils.e("APP", "TOGGLE");
}
});
super.onBindView(view);
}
The getFragmentManager is giving me error in the code. If i use Dialog preference i cant add a toggle button in right .How can i make Both interact ?
I am not able to find any reference related to this.Please help me out!!
解决方案
推荐阅读
- python - CherryPy:`error_page.default` 与 `error_page.404` 配置设置有什么区别?
- javascript - 如何使用父帐户令牌验证 Twilio 调用
- java - Android webview没有加载网址?
- javascript - Javascript将画布转换为img
- python - 将大对象传递给函数会影响速度吗?
- c++ - LLVM Pass:Demangle 库未与 pass 库链接
- java - 如何修复同一个 Maven 模块中的类的 ClassNotFoundException
- .net - 有人可以帮我理解这个正则表达式在做什么吗?
- python - 底图似乎缺少绘图视觉效果,例如蓝色大理石和某些投影
- node.js - 使用 Meteor + Multer 接收多部分表单数据?