android listview去除重复项,listview行中的TextView在Android中滚动时显示重复值?

我正在使用ListView的自定义适配器,其中我有一个TextView和一个Spinner.从Spinner中选择值后,将该值复制到相应行列表的TextView之后.

问题是,由于我在ListView中有超过40个元素,当我选择第一个微调器并将值设置为相应的TextView时,在滚动时,在第10行TextView中可以看到相同的值.

在滚动时将值从第1个TextView复制到第10个TextView.

以下是我使用的代码:

public class AppListAdapter extends BaseAdapter {

private LayoutInflater mInflater;

private List mApps = Constants.list;

private Context _activity;

ArrayList months=null;

ArrayAdapter dataAdapter =null;

int spinerposition;

int viewposition;

int temp=0;

private int screenWidth;

/**

* Constructor.

*

* @param context the application context which is needed for the layout inflater

* @param screenWidth

*/

public AppListAdapter(Context context, int screenWidth) {

// Cache the LayoutInflate to avoid asking for a new one each time.

mInflater = LayoutInflater.from(context);

this._activity=context;

this.screenWidth = screenWidth;

months = new ArrayList();

months.add("No Item Selected");

months.add("None");

months.add("Entertainment");

months.add("Games");

months.add("News/Books");

months.add("Social Networking");

months.add("Utilities");

months.add("Texting");

months.add("Web Browsers");

// Creating adapter for spinner

dataAdapter = new ArrayAdapter(_activity,

android.R.layout.simple_spinner_item, months);

// Drop down layout style - list view with radio button

dataAdapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice);

}

public int getCount() {

return mApps.size();

}

public Object getItem(int position) {

return mApps.get(position);

}

public long getItemId(int position) {

return position;

}

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

final AppViewHolder holder;

viewposition=position;

if(convertView == null) {

convertView = mInflater.inflate(R.layout.row, null);

// creates a ViewHolder and stores a reference to the children view we want to bind data to

holder = new AppViewHolder();

holder.spiner=(Spinner)convertView.findViewById(R.id.spinner);

holder.offtext=(TextView)convertView.findViewById(R.id.off_txt);

holder.offTxt = (TextView) convertView.findViewById(R.id.off_txt);

holder.apptitleTxt = (TextView) convertView.findViewById(R.id.apptitle_txt);

Typeface typeface = Typeface.createFromAsset(_activity.getAssets(),"CHICM___.TTF");

holder.apptitleTxt.setTypeface(typeface);

holder.offTxt.setTypeface(typeface);

if(screenWidth>480){

holder.offTxt.setTextSize(30);

holder.apptitleTxt.setTextSize(30);

}

convertView.setTag(holder);

} else {

holder = (AppViewHolder) convertView.getTag();

}

holder.setTitle(mApps.get(position).getTitle(),mApps.get(position).getVersionName());

notifyDataSetChanged();

holder.offTxt.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

holder.spiner.performClick();

}

});

holder.spiner.setAdapter(dataAdapter);

holder.spiner.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView> arg0, View arg1,int arg2, long arg3) {

spinerposition=arg2;

switch (spinerposition)

{

case 1:

holder.offtext.setText("None");

break;

case 2:

holder.offtext.setText("Entertainment");

break;

case 3:

holder.offtext.setText("Games");

break;

case 4:

holder.offtext.setText("News/Books");

break;

case 5:

holder.offtext.setText("Social Networking");

break;

case 6:

holder.offtext.setText("Utilities");

break;

case 7:

holder.offtext.setText("Texting");

break;

case 8:

holder.offtext.setText("Web Browsers");

break;

}

}

public void onNothingSelected(AdapterView> arg0) {

}

});

return convertView;

}

/**

* Sets the list of apps to be displayed.

*

* @param list the list of apps to be displayed

*/

public void setListItems(List list) {

mApps = list;

}

/**

* A view holder which is used to re/use views inside a list.

*/

public class AppViewHolder {

private TextView mTitle = null;

private TextView apptitleTxt = null;

private TextView offTxt = null;

private Spinner spiner=null;

public TextView offtext;

/**

* Sets the text to be shown as the app's title

*

* @param title the text to be shown inside the list row

*/

public void setTitle(String title,String category) {

apptitleTxt.setText(title);

// offtext.setText(category);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值