2017-08-26 57 views
-2

这是Main_Activity我的ListView不显示图像

Integer[] imgid = {R.drawable.frame3,R.drawable.frame3,R.drawable.frame3,R.drawable.frame3, 
      R.drawable.frame5,R.drawable.frame6,R.drawable.frame7,R.drawable.frame8, 
      R.drawable.frame9,}; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_edit_image_activity); 

     Bundle extras = getIntent().getExtras(); 
     byte[] byteArray = extras.getByteArray("image"); 
     Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 

     img_img=(ImageView)findViewById(R.id.img); 
     img_img.setImageBitmap(bmp); 


     Adapter adapter=new Adapter(this,imgid); 
     list=(ListView)findViewById(R.id.listview); 
     list.setAdapter(adapter); 
     Log.e("Your in Main","Welcome_______"); 

     list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       String pos=Integer.toString(position); 
       Toast.makeText(EditImageActivity.this, "Your Position is"+pos, Toast.LENGTH_SHORT).show(); 
      } 
     }); 
    } 
} 

这是适配器class___________

public class Adapter extends ArrayAdapter<String> { 

    private final Activity context; 
    private final Integer[] images; 

    public Adapter(Activity context, Integer[] imgid) { 
     super(context, R.layout.list_image); 
     this.context=context; 
     this.images=imgid; 

    } 

    @Override 
    public View getView(int position,View convertView,ViewGroup parent) { 

     Log.e("Your in getView","Welcome"); 
     LayoutInflater inflater=context.getLayoutInflater(); 
     View rowView=inflater.inflate(R.layout.list_image, null,true); 
     ImageView imageView = (ImageView) rowView.findViewById(R.id.list_img); 
     imageView.setImageResource(images[position]); 

     return rowView; 
    } 
} 
+0

有什么问题? – sushildlh

+0

首先,从数组中的最后一个元素中删除逗号..'imgid'。其次,它是否显示任何错误或什么? –

+0

getView方法在适配器类中不调用 –

回答

0

更新

View rowView=inflater.inflate(R.layout.list_image, null,true); 

View rowView=inflater.inflate(R.layout.list_image, null); 
+0

我已更新,但仍无法使用。 –