1
我是Android新手,我想顯示res
的位圖圖像和ListView
中的當前時間。時間顯示在ListView中,但圖像未顯示。 請任何人都可以幫助我。在列表視圖中顯示位圖圖像
我的代碼如下:
public class MainActivity extends Activity {
private int id;
static String TIME = "time";
static Bitmap BIMAGE;
private Time today = new Time(Time.getCurrentTimezone());
private Bitmap bMap;
private ListView listView;
private List<HashMap<String, Object>> values = new ArrayList<HashMap<String, Object>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list);
java.lang.reflect.Field[] list = R.drawable.class.getFields();
//for(int i=0;i<list.length;i++){
for (int i=0;i<9;i++){
try {
id = list[i].getInt(null);
today.setToNow();
//System.out.println("------------------"+id+"---------------");
bMap = BitmapFactory.decodeResource(getResources(), id);
bMap = Bitmap.createScaledBitmap(bMap, 50, 50, true);
//aImage.setImageBitmap(bMap);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("img", bMap);
map.put("time", today.format("%k:%M"));
values.add(map);
new CheckinDetail().execute();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
class CheckinDetail extends AsyncTask<String, String, String> {
@SuppressWarnings("deprecation")
protected String doInBackground(String... args) {
return null;
}
protected void onPostExecute(String file_url) {
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(MainActivity.this, values, R.layout.rowlayout, new String[] { "img","time"},new int[] { R.id.AImage, R.id.time});
listView.setAdapter(adapter);
listView.setCacheColorHint(Color.TRANSPARENT);
}
});
}
}
}
當然,你可以設置你自己的佈局偏好 – Shaho
嗨Shaho我想要使用列表適配器編程添加圖像 – user3212059