2017-06-01 89 views
-3

這是我的代碼:位圖轉換爲整數(安卓)

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); 

我需要轉換位映射到整數到可以使用該程序。

謝謝

+0

Integer是什麼意思?位圖是位圖。整數是整數。 – AlphaQ

+0

你能更清楚地知道你的問題是什麼嗎?是否可以看到你的問題和代碼之間沒有鏈接。 – corvairjo

+0

問題是我有一個位圖中的圖像,我得到這個在我的數據庫中 bitmap = BitmapFactory.decodeStream(conimagen.getInputStream());我需要展示很多圖片,所以我會有很多位圖。爲了顯示圖像我有一個適配器,圖像在Interger []中,爲此我需要轉換o另一個解決方案可以顯示我的圖像 –

回答

0

如果你想訪問的圖像,你與別人做這樣R.drawable.php的ID(這是一個int),你可以只使用R.mipmap.ic_launcher並用它來得到它在你的名單。

0

是的,這個作品中,問題是這樣的其它位圖:

URL urlimagen =新的URL(IMAGENES + alumnosJSON.getJSONObject(I).getString( 「rutaimagen」));

HttpURLConnection conimagen =(HttpURLConnection)urlimagen.openConnection();

conimagen.connect();

bitmap = BitmapFactory.decodeStream(conimagen.getInputStream());