0
如何顯示圖像爲簡單列表視圖如果這個圖像是位圖如何顯示圖像爲簡單列表視圖如果這個圖像是位圖
該空隙中的位圖加載圖像
private Bitmap loadImageFromStorage(String ImageName)
{
ContextWrapper cw = new ContextWrapper(mActivity.getApplicationContext());
// path to /data/data/yourapp/app_data/imageDir
File directory = cw.getDir("imageDir", Context.MODE_PRIVATE);
// Create imageDir
File path=new File(directory,ImageName+".jpg");
try {
Bitmap b = BitmapFactory.decodeStream(new FileInputStream(path));
// ImageView img=(ImageView)findViewById(R.id.imgPicker);
// img.setImageBitmap(b);
return b ;
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return null;
}
這是佈局從我的單個對象到列表
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:padding="5dp"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@color/accent_material_dark"
style="@style/stile"
android:id="@+id/imageViewID" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toEndOf="@+id/imageViewID">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome Gruppo"
android:id="@+id/NomeGruppo"
android:layout_alignParentTop="false"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="false"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#Gruppo"
android:id="@+id/IDgruppo"
android:layout_below="@+id/NomeGruppo"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:textColor="#6b6f6e" />
</LinearLayout>
這是我的老甲基外徑爲負載列表視圖沒有圖像
private void visualizzaRisultati(){
final List<Map<String, String>> lista = readDb();
String[] from = {"NomeGruppo", "IDgruppo"}; //dai valori contenuti in queste chiavi
int[] to = {R.id.NomeGruppo, R.id.IDgruppo};//agli id delle view
SimpleAdapter adapter = new SimpleAdapter(
mActivity.getApplicationContext(),
lista,//sorgente dati
R.layout.visualizza_ris_ric_gruppo, //layout contenente gli id di "to"
from,
to);
final ListView mylist = (ListView) getActivity().findViewById(R.id.listaGruppi);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
Intent nuovaPagina = new Intent(mActivity, gruppo.class);
nuovaPagina.putExtra("nomeGruppo", lista.get(position).get("IDgruppo").toString());
startActivity(nuovaPagina);
}
});
mylist.setAdapter(adapter);
}
protected List<Map<String, String>> readDb(){
SQLiteDatabase db;
db = getActivity().openOrCreateDatabase("utenteDB", Context.MODE_PRIVATE, null);
Cursor resultSet = db.rawQuery("Select * from gruppo",null);
List<Map<String, String>> lista = new ArrayList<Map<String, String>>();
if (resultSet.moveToFirst()) {
do {
final String idgruppo = resultSet.getString(0);
final String nomeGruppo =resultSet.getString(1);
lista.add(new HashMap<String, String>() {
{
put("NomeGruppo", nomeGruppo);
put("IDgruppo", idgruppo);
}
});
} while (resultSet.moveToNext());
}
return(lista);
}
我怎樣才能圖像升級此方法用於負載到佈局列表視圖
你應該使用自定義適配器 – NIPHIN
我該如何使用它? – robx