Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改Android ImageButton';当应用程序启动时,从Drawable文件夹中删除图像';开始了,有什么意图?_Android_Select_Drawable_Imagebutton - Fatal编程技术网

如何更改Android ImageButton';当应用程序启动时,从Drawable文件夹中删除图像';开始了,有什么意图?

如何更改Android ImageButton';当应用程序启动时,从Drawable文件夹中删除图像';开始了,有什么意图?,android,select,drawable,imagebutton,Android,Select,Drawable,Imagebutton,嗨,伙计们,你们能帮我吗 我想允许应用程序的用户更改ImageButton的图像,从Drawable文件夹的文件(png)中进行选择,我想我需要创建一个Inten。 我将此“事件”关联到OnLongClickListener之后 这是如何翻译成代码的 多谢各位! 亲切的问候这是我的回答 ImageView iv=(Imageview)findViewById(R.id.imageView1); //importing that imageview into code to set program

嗨,伙计们,你们能帮我吗

我想允许应用程序的用户更改ImageButton的图像,从Drawable文件夹的文件(png)中进行选择,我想我需要创建一个Inten。 我将此“事件”关联到OnLongClickListener之后

这是如何翻译成代码的

多谢各位! 亲切的问候这是我的回答

ImageView iv=(Imageview)findViewById(R.id.imageView1); //importing that imageview into code to set programmatically

public void button(View view){

iv.setImageResource(R.drawable.png1);
}

希望这能有所帮助。

在按钮上单击,您可以启动一个新的活动以获得结果,在此活动中,您可以显示可绘制文件夹中的所有图像 要启动活动,请使用:

Button b = (Button) findViewById(R.id.buttonId);
b.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View v) {
        Intent i = new Intent(this, MostraDrawableActivity.class);
        startActivityForResult(i, 7412);
    }

});
在MostraDrawableActivity中,要获取drawable文件夹中所有图像的名称,可以使用以下方法:

Field[] drawables = <your packagen name>.R.drawable.class.getFields();
for (Field f : drawables) {
    try {
        System.out.println("R.drawable." + f.getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
这样,当前活动将关闭,并将choosen drawable的名称“传递回”原始活动

现在,当我们必须像这样覆盖OnActivityResult方法并设置按钮的背景图像时,我们可以返回到原始活动:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 7412) {
        if(resultCode == RESULT_OK){      
                      b.setBackgroundResource(getResources().getIdentifier(data.getStringExtra("nomeDrawableScelto"), "drawable",getPackageName()));
         }

      }
    }//onActivityResult
编辑以填充列表视图

ArrayList<String> foto = new ArrayList<String>();
Field[] drawables = <your packagen name>.R.drawable.class.getFields();
for (Field f : drawables) {
    try {
        foto.add("R.drawable." + f.getName());
        //System.out.println("R.drawable." + f.getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}



// Create the array adapter to bind the array to the listView
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(  this, 
                            android.R.layout.simple_list_item_1,
                            foto 
                        );
myListView.setAdapter(aa);
ArrayList foto=new ArrayList();
字段[]drawables=.R.drawable.class.getFields();
用于(字段f:可抽出式){
试一试{
add(“R.drawable.+f.getName());
//System.out.println(“R.drawable.+f.getName());
}捕获(例外e){
e、 printStackTrace();
}
}
//创建阵列适配器以将阵列绑定到listView
最终阵列适配器aa;
aa=新阵列适配器(此,
android.R.layout.simple\u list\u item\u 1,
福托
);
myListView.setAdapter(aa);

因此,您有一个imageview,需要根据按键以编程方式对其进行更新。我说的对吗?是的,先生,当用户点击Imagebutton时,他可以在Drawable文件夹中的png文件中选择Imagebutton的图像。谢谢Yogamurthy,但我想允许用户在应用程序中从res/Drawable更改图像,用户将如何更改它。你有按钮、微调器或其他东西吗?有一个ImageButton,点击后用户可以从res/drawable文件夹中选择新的ImageButton图像,非常感谢!用户将如何查看可绘制文件夹中的图像列表?是随机选择的图片吗?Grazie Alessandro,il mio problemaèun po'diverso,vorrei che l'utente potesse scegliere le immagini dalla cartella可绘制的专有图像按钮cliccato,il mio inglese fa pena,gentilissimoah ho capito..意大利语初级学院!:-)在斯芬多,一个冒名顶替的人,一个可画的画,一个不可画的名字。。。我不想修改每一份关于bottone的关税。。。来吧,让我们一起来看一看这部电影吧,格拉齐,帕吉纳,萨雷布·佩尔弗托,我的《漫画》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的《我的女儿》,苏拉的《我的女儿》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的故事》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的《我的女儿》里的故事》。Su youtube cèun教程,ma li le carica dalla galleria del telefono,grazie mille!如何修改mia Rispesta..不需要使用图蒂i passaggi siano chiari,每一个字母都有一个字母…只需使用纯scrivi…Sono pessimo,alla riga Field[]drawables=android.R.drawable.class.getFields();mi da questo错误,类型不匹配:无法从字段[]转换为格式。字段[]
ArrayList<String> foto = new ArrayList<String>();
Field[] drawables = <your packagen name>.R.drawable.class.getFields();
for (Field f : drawables) {
    try {
        foto.add("R.drawable." + f.getName());
        //System.out.println("R.drawable." + f.getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}



// Create the array adapter to bind the array to the listView
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(  this, 
                            android.R.layout.simple_list_item_1,
                            foto 
                        );
myListView.setAdapter(aa);