小编tar*_*tar的帖子

在Android中调整Drawable的大小

我正在为进度对话框设置一个drawable(pbarDialog)但我的问题是我想每次调整drawable的大小但是无法弄清楚如何.

这是一些代码:

Handler progressHandler = new Handler() {

    public void handleMessage(Message msg) {
        switch (msg.what) {
            // some more code
            case UPDATE_PBAR:
                pbarDialog.setIcon(mAppIcon);
                pbarDialog.setMessage(mPbarMsg);
                pbarDialog.incrementProgressBy(mIncrement+1);
                break;
        }
    }
};

pbarDialog.show();

Thread myThread = new Thread(new Runnable() {

    public void run() {
        // some code
        for (int i = 0; i < mApps.size(); i++) {
            mAppIcon = mAdapter.getIcons().get(mApps.get(i).getPackageName());
            // need to resize drawable here
            progressHandler.sendEmptyMessage(UPDATE_PBAR);
        }
        handler.sendEmptyMessage(DISMISS_PBAR);
    }

});

myThread.start();
Run Code Online (Sandbox Code Playgroud)

android resize image bitmap drawable

34
推荐指数
4
解决办法
8万
查看次数

django模板,查找字符串替换为其他字符串

Hay,我正在编写一些模板,但我想在字符串中将""转换为"_".

我想转换输出

{{ user.name }}
Run Code Online (Sandbox Code Playgroud)

从"我的名字"到"我的名字"之类的东西.我该怎么做呢?

django templates

28
推荐指数
3
解决办法
5万
查看次数

通过后退按钮关闭弹出窗口

我想通过单击弹出窗口外部或后退按钮来关闭弹出窗口,但是当单击后退按钮我的应用程序退出时,而不是退出应用程序我想要关闭弹出窗口.

这是我的代码,

ivmainmenu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            LayoutInflater layoutInflater 
             = (LayoutInflater)getBaseContext()
              .getSystemService(LAYOUT_INFLATER_SERVICE);  
            View popupView = layoutInflater.inflate(R.layout.popupwindow, null);  
          final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.FILL_PARENT,
                  LayoutParams.WRAP_CONTENT);  
                popupWindow.showAsDropDown(ivmainmenu, 0,14);
                popupView.setPadding(0, 0, 0, 10);
                popupWindow.showAsDropDown(ivmainmenu);

                popupWindow.setBackgroundDrawable(new BitmapDrawable());
                popupWindow.setOutsideTouchable(false);

                TextView tvpopupwork = (TextView)popupView.findViewById(R.id.tvpopupwork);
                TextView tvpopupabout = (TextView)popupView.findViewById(R.id.tvpopupabout);
                TextView tvpopupservices = (TextView)popupView.findViewById(R.id.tvpopupservices);
                TextView tvpopupcontact = (TextView)popupView.findViewById(R.id.tvpopupcontact);

                Typeface typeFace2 =  Typeface.createFromAsset(getAssets(),"fonts/arboriaboldregular.ttf");
                tvpopupwork.setTypeface(typeFace2);
                tvpopupabout.setTypeface(typeFace2);
                tvpopupservices.setTypeface(typeFace2);
                tvpopupcontact.setTypeface(typeFace2);

                tvpopupwork.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method …
Run Code Online (Sandbox Code Playgroud)

android android-popupwindow

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

Clojure:命名匿名函数

在Clojure中,何时以及为什么要使用命名的匿名函数?例如,

((fn add-five [x] (+ x 5)) 3))
Run Code Online (Sandbox Code Playgroud)

在ClojureDocs中,一个例子的评论说它在堆栈跟踪中很有用.可以举个例子吗?

clojure

11
推荐指数
3
解决办法
402
查看次数

Django模型避免重复

在模型中:

class Getdata(models.Model):
    title = models.CharField(max_length=255)
    state = models.CharField(max_length=2, choices=STATE, default="0")
    name = models.ForeignKey(School)
    created_by = models.ForeignKey(profile)

    def __unicode__(self):
        return self.id()
Run Code Online (Sandbox Code Playgroud)

在模板中:

<form>
    <input type="submit" value="save the data" />
</form> 
Run Code Online (Sandbox Code Playgroud)

如果用户单击保存按钮并且上述数据保存在表中,如何避免重复,即如果用户再次单击相同的提交按钮,则不应该有相同值的另一个条目.或者它是否必须在视图中处理?

python django django-templates django-models django-views

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

如何使Xml架构中的元素成为optinal

我有一个元素,我需要使其可选.

<xs:element name="Version" type="xs:string" minOccurs="1" />
Run Code Online (Sandbox Code Playgroud)

除了制作之外还有其他方法minOccurs="0"吗?

xml xsd

3
推荐指数
1
解决办法
1591
查看次数

Android:字符串值未进入共享首选项

我已经为布尔值和字符串值创建了共享首选项.布尔值在另一个活动中获得.但对于字符串我只获得默认值.

Home.class

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor spe = prefs.edit();

    spe.putBoolean("flag", true); 
    spe.putString("user", "hello");
    spe.commit(); 
Run Code Online (Sandbox Code Playgroud)

welcome.class

      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean flag= prefs.getBoolean("flag", false); 
    String user=prefs.getString("user","Nothing");  

      TextView tv = new TextView(this);
      tv.setText("Flag : "+flag+(" User : "+user);
Run Code Online (Sandbox Code Playgroud)

对于"用户",仅显示"无".我应该在哪里更正我的代码?

android sharedpreferences

3
推荐指数
1
解决办法
8843
查看次数

Django模板列表

我对Django比较新,我有一个简单的问题.在我的模板中,我有:

{% for article in article_list %}
<li>
{% for author in article.authors.all %}
        {{ author.name }}, 
{% endfor %}
{{ article.title }}
</li>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

我想要的是能够迭代author.name,但姓氏应该以句点而不是逗号结束.我是否必须返回视图才能实现此目的,或者模板中是否有一些简单的方法?

django templates

0
推荐指数
1
解决办法
111
查看次数

LinkedHashMap中的NullPointerException

我在创造一个游戏.当我正在阅读LinkedHashMap时,它给了我一个NPE.

我这样填写LinkedHashMap hm:

for (String s : line.split("")) {
    if (s.contains("*")) {
        hm.put(new Coordinates(xa-32, ya), "gray");
    } else if (s.contains("#")) {
        hm.put(new Coordinates(xa-32, ya), "black");
    }
    // other code...
}
Run Code Online (Sandbox Code Playgroud)

后来我尝试从这样的HashMap中获取颜色,并得到一个NPE:

if ((keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_A)
    && isPainted && hm.get(new Coordinates(x - 32, y)).equalsIgnoreCase("gray")) {
    x -= 32;
}
Run Code Online (Sandbox Code Playgroud)

完整代码:

java nullpointerexception linkedhashmap

-10
推荐指数
2
解决办法
1664
查看次数