这是我的代码:
public class MainActivity extends Activity {
private String lenguajeProgramacion[]=new String[]{"Java","PHP","Python","JavaScript","Ruby","C",
"Go","Perl","Pascal"};
private Integer[] imgid={
R.drawable.php,
R.drawable.python,
R.drawable.javascript,
R.drawable.ruby,
R.drawable.c,
R.drawable.go,
R.drawable.perl,
R.drawable.pascal
};
private ListView lista;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LenguajeListAdapter adapter=new LenguajeListAdapter(this,lenguajeProgramacion,imgid);
lista=(ListView)findViewById(R.id.mi_lista);
lista.setAdapter(adapter);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String Slecteditem= lenguajeProgramacion[+position];
Toast.makeText(getApplicationContext(), Slecteditem, Toast.LENGTH_SHORT).show();
}
});
}
}
我有这个:
Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
我需要将此位图转换为Integer才能使用该程序。
谢谢
答案 0 :(得分:0)
如果您尝试访问图像的ID(int
),就像使用R.drawable.php
之类的其他人一样,您可以使用R.mipmap.ic_launcher
并使用它把它放在你的清单中。
答案 1 :(得分:0)
是的,这很有效,问题在于其他位图:
网址urlimagen =新网址(IMAGENES + alumnosJSON.getJSONObject(i).getString(“rutaimagen”));
HttpURLConnection conimagen =(HttpURLConnection)urlimagen.openConnection();
conimagen.connect();
bitmap = BitmapFactory.decodeStream(conimagen.getInputStream());