我在列表视图中获取getview中的重复数据。可以任何人给出解决方案。 我的代码是:
主要活动
package com.example.listviewtest;
import android.content.Context;
import android.database.DataSetObserver;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ListAdapter;
public class MyListAdapter implements ListAdapter {
MainActivity mainActivity;
private ViewHolder holder;
private String[] scoresToUpdate=new String[1000] ;
public MyListAdapter(MainActivity mainActivity) {
this.mainActivity=mainActivity;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 20;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getItemViewType(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View convertView, ViewGroup arg2) {
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater vi = (LayoutInflater)
mainActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.element_in_game, null);
holder.scoreToUpdate = (EditText) convertView
.findViewById(R.id.txt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final int tmp_position=arg0;
holder.scoreToUpdate.setText(scoresToUpdate[tmp_position]);
holder.scoreToUpdate.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
scoresToUpdate[tmp_position] = s.toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
return convertView;
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isEnabled(int arg0) {
// TODO Auto-generated method stub
return true;
}
class ViewHolder {
public EditText scoreToUpdate;
}
}