小编usr*_*und的帖子

在SharedPreferences中存储数组列表对象

此方法将新对象添加到 ArrayList

//get text from textview
time = date.getText().toString();
entry_d = entry.getText().toString();
dayName = day.getText().toString();

arrayList.add( new ArrayObject( dayName, entry_d ,time));
Run Code Online (Sandbox Code Playgroud)

我正在尝试添加这3个字符串SharedPrefrences.这是我的代码:

private void savePreferences(String key, String value) {

    SharedPreferences sharedPreferences = PreferenceManager             
                                     .getDefaultSharedPreferences(this);
    Editor editor = sharedPreferences.edit();
    editor.putBoolean(key, value);
    editor.commit();
}
Run Code Online (Sandbox Code Playgroud)

此方法一次只添加一个字符串,因为我想一次添加3个字符串.有什么方法我可以实现.

android sharedpreferences

19
推荐指数
2
解决办法
5万
查看次数

Javascript跨域JSON

嗨,我正在尝试使用ONLY JavaScript并从URL HTML读取json对象.我使用以下代码:

function getJSONP(url, success) {

    var ud = '_' + +new Date,
        script = document.createElement('script'),
        head = document.getElementsByTagName('head')[0]
            || document.documentElement;

    window[ud] = function(data) {
        head.removeChild(script);
        success && success(data);
    };

    script.src = url.replace('callback=?', 'callback=' + ud);
    head.appendChild(script);
}

getJSONP('http://webURl?&callback=?', function(data){
    console.log(data);
});
Run Code Online (Sandbox Code Playgroud)

正如你猜想的那样 Not at same origin as the document, and parent of track element does not have a 'crossorigin' attribute. Origin 'null' is therefore not allowed access.

仅供参考,服务器返回JSON数据,但没有回调函数.

干杯,为您提供帮助.

javascript jsonp cross-domain

9
推荐指数
1
解决办法
1148
查看次数

JButton背景图片

您好我正在尝试为JButton实现Action侦听器,代码如下所示:

ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png"));
one = new JButton("",imageForOne);
one.setPreferredSize( new Dimension(78, 76));
one.addActionListener(myButtonHandler);
Run Code Online (Sandbox Code Playgroud)

使用上面的JButton看起来很好有关按钮1,请参见下图

当我为按钮添加特定值时,例如

ImageIcon imageForOne = new ImageIcon(getClass().getResource("resources//one.png"));
//Check this
one = new JButton("one",imageForOne);
one.setPreferredSize( new Dimension(78, 76));
one.addActionListener(myButtonHandler);
Run Code Online (Sandbox Code Playgroud)

它看起来像下图

检查按钮1

有什么办法可以避免这种情况并设定价值.

感谢您的帮助.

java swing jbutton actionlistener imageicon

5
推荐指数
1
解决办法
2万
查看次数

Android意图,片段和活动

我知道很多人会指导我使用API​​.我越来越糊涂我了解更多的Intent FragmentActivity.任何人都可以描述这些是什么以及为什么这三个对于Android应用程序开发过程很重要?

谢谢你的帮助提前.

android android-intent android-fragments android-activity android-fragmentactivity

3
推荐指数
2
解决办法
832
查看次数

Android 将 <String> 设置为数组

我是安卓编程新手。我已保存数据sharedPreference并取回数据并存储如下

        Set <String> set = sharedPref.getStringSet(dayName, null);
Run Code Online (Sandbox Code Playgroud)

Set <String> set将 3 个数组存储在一行 arrayOne、arrayTwo、arrayThree 中,并带有TAG. 有什么办法可以将其转换为数组并单独保存。

谢谢您的帮助。

arrays android

2
推荐指数
1
解决办法
9907
查看次数