我正在使用listView来填充来自webservice的数据,我正在根据json中的webservice所需的结果完成,但是当我在listview中的适配器中设置它时它只给我重复的行,我也检查了我的arraylist是完美的。
public class ListingAdapter extends BaseAdapter {
private Activity mContext;
ArrayList<Bussiness> busList;
public ListingAdapter(Activity c, ArrayList<Bussiness> busList) {
mContext = c;
this.busList = busList;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return busList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View grid;
LayoutInflater inflater = (LayoutInflater) mContext.getLayoutInflater();
if (convertView == null) {
grid = new View( mContext );
grid = inflater.inflate( R.layout.raw_tab, null );
TextView tv_cat = (TextView) grid.findViewById( R.id.tv_cat );
ImageView iv_pic = (ImageView) grid.findViewById( R.id.iv_pic );
TextView tv_features = (TextView) grid.findViewById( R.id.tv_features );
TextView tv_location = (TextView) grid.findViewById( R.id.tv_location );
TextView tv_rating = (TextView) grid.findViewById( R.id.tv_rating );
RatingBar rt_bar = (RatingBar) grid.findViewById( R.id.rt_fvrt );
TextView tv_votes = (TextView) grid.findViewById( R.id.tv_votes );
ImageView iv_call = (ImageView) grid.findViewById( R.id.iv_call );
ImageView iv_share = (ImageView) grid.findViewById( R.id.iv_share );
tv_cat.setText( busList.get( position ).getBiz_name() );
tv_features.setText( busList.get( position ).getFeatures() );
tv_location.setText( busList.get( position ).getCity() );
tv_rating.setText( busList.get( position ).getAverage_rate() );
tv_votes.setText( busList.get( position ).getVotes() );
rt_bar.setRating( Float.parseFloat( busList.get( position ).getAverage_rate() ) );
if(!busList.get( position ).getImg_1().equals( "" )){
Picasso.with( mContext )
.load( busList.get( position ).getImg_1().replaceAll(" ", "%20") )
.placeholder( R.drawable.ic_no_img )
.error( R.drawable.ic_no_img )
.into( iv_pic );
}
iv_call.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent( Intent.ACTION_CALL );
intent.setData( Uri.parse( "tel:" + (busList.get( position ).getMobile_1()) ) );
if (ActivityCompat.checkSelfPermission( mContext, Manifest.permission.CALL_PHONE ) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mContext.startActivity( intent );
}
} );
iv_share.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent sharingIntent = new Intent( Intent.ACTION_SEND );
sharingIntent.setType( "text/html" );
sharingIntent.putExtra( android.content.Intent.EXTRA_TEXT, Html.fromHtml( "TEst From all About City." ) );
mContext.startActivity( Intent.createChooser( sharingIntent, "Share using" ) );
}
} );
} else {
grid = (View) convertView;
}
return grid;
}
}
答案 0 :(得分:-1)
只需更改 ListingAdapter 类中的getItemId()
,如下所示
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}