看源码吧  因为我从服务器上获取到了文字 但要在文字旁边加图片 要不一样的图片的 怎么添加?
ListView_tab继承ACtivitypublic class ListView_tab extends Activity implements OnItemClickListener {
    private ArrayList<GamesCategory> gamesCategoryList = null;
    private GamesCategoryAdapter categoryAdapter = null;
    ListView list;
    private ArrayList<HashMap<String, Object>> mData;
    private GamesCategoryAdapter  listViewAdapter;
    private List<Map<String, Object>> listItems;
    private static final int MSG_SUCCESS = 0;// 成功的标识
    private static final int MSG_FAILURE = 1;// 失败的标识
    private Thread mThread;
    private ProgressDialog progressDialog;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_SUCCESS:
                    categoryAdapter = new GamesCategoryAdapter(ListView_tab.this, gamesCategoryList);
                    list.setAdapter(categoryAdapter);
                    progressDialog.dismiss();
                    break;
                case MSG_FAILURE:
                    progressDialog.dismiss();
                    AlertDialog.Builder builder = new Builder(ListView_tab.this);
                    builder.setTitle("失败");
                    builder.setPositiveButton("确定", null);
                    builder.setIcon(R.drawable.icon);
                    builder.setMessage("无法连接服务器,请检查网络设置");
                    builder.show();
                    break;
            }
        }
    };    @Override
    protected void onCreate(Bundle savedInstanceState) {        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        Log.v("ListView_tab", "onCreate");
        setContentView(R.layout.listview_tab);
        progressDialog = ProgressDialog.show(ListView_tab.this, "请稍等...", "获取数据中...", true);
        progressDialog.setIcon(R.drawable.icon);
        if (mThread == null) {
            mThread = new Thread(runnable);
            mThread.start();
        } else {
            Log.v("wjp", "wetret");
        }
        list = (ListView) findViewById(R.id.list);
 
        list.setOnItemClickListener(this);
        
    }    Runnable runnable = new Runnable() {        @Override
        public void run() {
            try {
                gamesCategoryList = WebHelper.getGameCategory(ListView_tab.this);//传过去参数得到文字信息
                if (gamesCategoryList != null) {
                    mHandler.obtainMessage(MSG_SUCCESS, list).sendToTarget();
                } else {
                   
                    mHandler.obtainMessage(MSG_FAILURE, list).sendToTarget();
                }
            } catch (Exception e) {
              
                e.printStackTrace();
            }
        }
    };    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        GamesCategory info = null;
        info = gamesCategoryList.get(position);
        Intent intent = new Intent();
        intent.setClass(ListView_tab.this, listViewDetailed.class);
        Bundle mBundle = new Bundle();
        mBundle.putString("type_id", info.getTypeId());
        intent.putExtras(mBundle);
        startActivity(intent);    }}GamesCategoryAdapter适配器类public class GamesCategoryAdapter extends BaseAdapter {
    private List<GamesCategory> list = null;
    private Context context = null;
    private List<Map<String,Object>>listItems;
    private LayoutInflater mInflater = null;    public GamesCategoryAdapter(Context context, List<GamesCategory> list) {
        this.list = list;
        this.context = context;
        this.mInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }    @Override
    public Object getItem(int position) {
        return list.get(position);
    }    @Override
    public long getItemId(int position) {
        return position;
    }    @Override
    public View getView(int position, View convertView, ViewGroup parent) {    
        GamesCategory gamesCategory = list.get(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.list_item, null);
        }
        
        TextView categoryTv;
        ImageView iv;
        iv =(ImageView)convertView.findViewById(R.id.img);
        categoryTv = (TextView)convertView.findViewById(R.id.title);
        categoryTv.setText(gamesCategory.getTypeName());
        return convertView;
        
       
        
    }}帮忙看些一下代码怎么在每个item上添加图片

解决方案 »

  1.   

    你gamesCategory对象应该有图片的对象吧。
    有的话不就直接对布局上的这个进行赋值就可以了么。
      

  2.   


    有10几个item   每个item是不一样的图片本地的图片  你说的gamesCategory  那都是显示一个图片的。我之前设置过 
      

  3.   

    首先你要把图片存到一个数组中去,什么样的问题,对应什么样子的文字,自己做个映射,然后在
    getView中设置图片,文字就可以了。具体的layout的话,可以用lnearlayout或者是relativelayout,自己选择,里面就是放 icon, text ,icon.背景的话,看你是用图片,还是用android的shape了,自己选择就是了