- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 fragment ,我尝试从列表中获取我的设置值,购买它时找不到 findPreference 方法,为什么?
package com.cetabo.trackingpoint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
import com.cetabo.trackingpoint.dummy.DummyContent;
import com.cetabo.trackingpoint.util.DetectionLocation;
import java.util.Date;
/**
* A fragment representing a list of Items.
* <p/>
* Large screen devices (such as tablets) are supported by replacing the ListView
* with a GridView.
* <p/>
* Activities containing this fragment MUST implement the {@link OnFragmentInteractionListener}
* interface.
*/
public class PlacesFragment extends Fragment implements AbsListView.OnItemClickListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
/**
* The fragment's ListView/GridView.
*/
private AbsListView mListView;
ImageView imageView;
/**
* The Adapter which will be used to populate the ListView/GridView with
* Views.
*/
private ListAdapter mAdapter;
// TODO: Rename and change types of parameters
public static PlacesFragment newInstance(String param1, String param2) {
PlacesFragment fragment = new PlacesFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public PlacesFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
// TODO: Change Adapter to display your content
// mAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, DummyContent.ITEMS);
}
String[] test ={"test","test"};
String text = "Central Park";
Date data = new Date();
//---HERE IS MY PROBLEM---
ListPreference listPreference = (ListPreference) findPreference("sync_frequency");
//------------------------
// Resources res = getResources();
// String[] time = res.getStringArray(R.array.pref_example_list_values);
// ArrayAdapter<String> adapter = ArrayAdapter.createFromResource(this, R.array.pref_sync_frequency_values, android.R.layout.simple_spinner_item);
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_place, container, false);
Context ctx = view.getContext();
DetectionLocation detectionLocation = new DetectionLocation(ctx);
CustomListAdapter adapter=new CustomListAdapter(getActivity(),test,String.valueOf(detectionLocation.getLongitude()+" "+detectionLocation.getLatitude()),data);
mListView = (AbsListView) view.findViewById(android.R.id.list);
mListView.setAdapter(adapter);
// Set OnItemClickListener so we can be notified on item clicks
mListView.setOnItemClickListener(this);
return view;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// try {
// mListener = (OnFragmentInteractionListener) activity;
// } catch (ClassCastException e) {
// throw new ClassCastException(activity.toString()
// + " must implement OnFragmentInteractionListener");
// }
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
}
}
/**
* The default content for this Fragment has a TextView that is shown when
* the list is empty. If you would like to change the text, call this method
* to supply the text it should use.
*/
public void setEmptyText(CharSequence emptyText) {
View emptyView = mListView.getEmptyView();
if (emptyView instanceof TextView) {
((TextView) emptyView).setText(emptyText);
}
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(String id);
}
}
最佳答案
因为,
如果您使用的是 API 级别 11+ 设备,findPreference()
是来自 PreferenceFragment
的方法。或者/否则,它将来自 PreferenceActivity
。
有关更多信息,请查看http://developer.android.com/reference/android/preference/PreferenceActivity.html
关于java - 找不到符号方法 findPreference(String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30063068/
当我检查 SharedPreferences 设置指南时,我发现它们同时使用:getPreferenceScreen().findPreference()和findPreference() 就像下面的
我正在尝试实用地将 SwitchPreferenceCompat 的切换开关更改为 true 和 false。但是,在 SettingsFragment 类中,方法 ammendSwitchPrefe
我有一个 fragment ,我尝试从列表中获取我的设置值,购买它时找不到 findPreference 方法,为什么? package com.cetabo.trackingpoint; impor
因此,SettingsActivity 实现了一个 SettingsFragment。我正在学习 Udacity 类(class)。我的主要问题是,findPreference() 不起作用!这是de
当我尝试在 SettingsFragment 中查找 Preference 时,我总是得到 NULL。 设置 fragment public static class SettingsFragment
当我尝试在我的 MainActivity 中初始化 OnSharedPreferencesChanged 监听器时,出现编译器错误无法解析方法 findPreference。根据回答here : fi
我遇到的问题是方法 findPreference 总是返回 null。我已经多次检查 key (即“pref_about”)是否正确,确实如此。 public class SettingsFragme
我正在尝试通过在主菜单中添加电池百分比来修改氰基模组设置 apk,但由于以下错误,我无法这样做:“方法 findPreference(string)”未定义” 我听说你只能从首选项 fragment
我目前正在尝试制作一个设置菜单,它将显示一个 MultiSelectListPreference,以从您的联系人列表中选择多个联系人。 此刻,当我尝试 MultiSelectListPreferenc
我正在处理我的 Android 应用程序的首选项屏幕。如果前一个项目具有特定值,我想禁用(将其灰显)。 我实现了两个类:MainActivity 和 PreferencesActivity。 在 Ma
我想检测 ListView 中包含的 Preference 何时被点击,以便我可以启动一个 Intent 来管理该选择。 我会在我的布局 XML 文件中这样做: 我的 java 代码中有以下内容:
它给我错误“findPreference(java.lang.CharSequence) is deprecated”。目前,我的应用程序的目标是 API 10 及更高版本。任何解决此问题的帮助都将不
我正尝试在与 PreferenceActivity 无关的 Activity 之外使用此代码。我正在尝试这样做,以便我可以访问我的偏好值。 Preference prefNotify = findPr
我想设置一个偏好摘要,通常可以用 EditTextPreference Pref = (EditTextPreference) findPreference(key); Pref.se
我是一名优秀的程序员,十分优秀!