从对话首选项继承时无法设置首选项

时间:2016-05-31 10:14:46

标签: android preference

我创建了一个扩展对话首选项的自定义首选项,就像编辑文本首选项一样。

关键区别在于我使用 PreferenceManager.setDefaultValues(mContext, preferences, true);

与标准java.lang.ClassCastException: customcontrols.TogglePreferenceTest cannot be cast to android.preference.Preference

相对应

e.g。

import android.support.v7.preference.EditTextPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import android.support.v7.preference.PreferenceManager;
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener{ 

如果我打电话

TogglePreferenceTest cannot be cast to android.support.v7.preference.Preference

然后我收到错误

PreferenceManager.setDefaultValues(mContext, preferences, true);

如果我将DialogPreference更改为标准版本,那么我在启动时不会崩溃,但是当我进入我的设置屏幕时,定义为

import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.ext.Attributes2Impl;
import javax.xml.parsers.ParserConfigurationException;

class MySlurper extends XmlSlurper {    
    public static final String LINE_NUM_ATTR = "_srmLineNum"
    Locator locator

    public MySlurper() throws ParserConfigurationException, SAXException {
        super();
    }

    @Override
    public void setDocumentLocator(Locator locator) {
        this.locator = locator;
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        Attributes2Impl newAttrs = new Attributes2Impl(attrs);        
        newAttrs.addAttribute(uri, LINE_NUM_ATTR, LINE_NUM_ATTR, "ENTITY", "" + locator.getLineNumber());        
        super.startElement(uri, localName, qName, newAttrs);
    }
}

def text = '''
<root>
  <a>one!</a>
  <a>two!</a>
</root>'''

def root = new MySlurper().parseText(text)

root.a.each { println it.@_srmLineNum }

然后它与function handleFileSelect(evt) { var files = evt.target.files; // FileList object // Loop through the FileList and render image files as thumbnails. for (var i = 0, f; f = files[i]; i++) { // Only process image files. if (!f.type.match('image.*')) { continue; } var reader = new FileReader(); // Closure to capture the file information. reader.onload = (function (theFile) { return function (e) { // Render thumbnail. var span = document.createElement('span'); //That's what i tried e.target.result.height=770; e.target.result.width=336; span.innerHTML = ['<img class="thumb" src="', e.target.result, '" title="', escape(theFile.name), '"/>'].join(''); document.getElementById('list').insertBefore(span, null); }; })(f); // Read in the image file as a data URL. reader.readAsDataURL(f); } } document.getElementById('files').addEventListener('change', handleFileSelect, false);

崩溃

我该怎么办?!为什么我不能使用
sudo chown -R yarn:yarn /data/var/log/hadoop-yarn 有支持类吗?特别是考虑到android.support.v7.preference.DialogPreference扩展了首选项,虽然技术上它扩展了android.support.v7.preference.Preference

0 个答案:

没有答案