Android 在gridview中插入分级栏
我在GridView中插入一个评级条,当我在这里使用setRating时,应用程序被强制关闭。这个Android 在gridview中插入分级栏,android,gridview,Android,Gridview,我在GridView中插入一个评级条,当我在这里使用setRating时,应用程序被强制关闭。这个rateFArr[]是一个浮点数组,当我在这里打印值时,我得到了它。但当我将它设置为分级栏时,它仍然不起作用 请帮我修一下,谢谢 我无法设置评级。。。现在,我用5个imageview制作了自己的评级栏,每个都有一个默认的空星图像,根据我得到的评级,我用半满星图像或全满星图像填充它,或者将其保留为空。这是我做的代码 public View getView(int position, View con
rateFArr[]
是一个浮点数组,当我在这里打印值时,我得到了它。但当我将它设置为分级栏时,它仍然不起作用
请帮我修一下,谢谢 我无法设置评级。。。现在,我用5个imageview制作了自己的评级栏,每个都有一个默认的空星图像,根据我得到的评级,我用半满星图像或全满星图像填充它,或者将其保留为空。这是我做的代码
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View grid=inflater.inflate(R.layout.griditem, parent, false);
imageView=(ImageView)grid.findViewById(R.id.grid_prod);
imageView.setImageResource(imgId[position]);
imgoff =(ImageView)grid.findViewById(R.id.offer);
tv=(TextView)grid.findViewById(R.id.grid_text);
tv.setText(namesArr[position]);
tv.setTextColor(Color.BLACK);
rb=(RatingBar)findViewById(R.id.grid_rating);
rb.setRating(rateFArr[position]);
return grid;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View grid=inflater.inflate(R.layout.griditem, parent, false);
imageView=(ImageView)grid.findViewById(R.id.grid_prod);
imageView.setImageResource(imgId[position]);
imgoff =(ImageView)grid.findViewById(R.id.offer);
tv=(TextView)grid.findViewById(R.id.grid_text);
tv.setText(namesArr[position]);
tv.setTextColor(Color.BLACK);
tv.setPadding(0, 2, 0, 0);
sta=(ImageView)grid.findViewById(R.id.imageView);
sta1=(ImageView)grid.findViewById(R.id.imageView1);
sta2=(ImageView)grid.findViewById(R.id.imageView2);
sta3=(ImageView)grid.findViewById(R.id.imageView3);
sta4=(ImageView)grid.findViewById(R.id.imageView4);
Float rate=rateFArr[position];
if(rate==5 || rate==4.5)
{
sta.setImageResource(R.drawable.full__small);
sta1.setImageResource(R.drawable.full__small);
sta2.setImageResource(R.drawable.full__small);
sta3.setImageResource(R.drawable.full__small);
if(rate==4.5)
{
sta4.setImageResource(R.drawable.half_small);
}
else
{
sta4.setImageResource(R.drawable.full__small);
}
}
if(rate==4 || rate==3.5)
{
sta.setImageResource(R.drawable.full__small);
sta1.setImageResource(R.drawable.full__small);
sta2.setImageResource(R.drawable.full__small);
if(rate==3.5)
{
sta3.setImageResource(R.drawable.half_small);
}
else
{
sta3.setImageResource(R.drawable.full__small);
}
}
if(rate==3 || rate==2.5)
{
sta.setImageResource(R.drawable.full__small);
sta1.setImageResource(R.drawable.full__small);
if(rate==2.5)
{
sta2.setImageResource(R.drawable.half_small);
}
else
{
sta2.setImageResource(R.drawable.full__small);
}
}
if(rate==2 || rate==1.5)
{
sta.setImageResource(R.drawable.full__small);
if(rate==1.5)
{
sta1.setImageResource(R.drawable.half_small);
}
else
{
sta1.setImageResource(R.drawable.full__small);
}
}
if(rate==1 || rate==0.5)
{
if(rate==1)
sta.setImageResource(R.drawable.full__small);
else
sta.setImageResource(R.drawable.half_small);
}
if(rate>5)
{
sta.setImageResource(R.drawable.full__small);
sta1.setImageResource(R.drawable.full__small);
sta2.setImageResource(R.drawable.full__small);
sta3.setImageResource(R.drawable.full__small);
sta4.setImageResource(R.drawable.full__small);
}
// rb=(RatingBar)findViewById(R.id.grid_rating);
//rb.setRating(rateFArr[position]);
return grid;
}