我正在构建一个appview,其中有一个listview(To-Do-List),这个listview正在从SQLite DB中填充。这是适配器:
public class ToDoListAdapter extends BaseAdapter implements OnClickListener{
private Context activity;
List<String> content,status;
private float x1,x2;
static final int MIN_DISTANCE = 150;
private LayoutInflater inflater=null;
public ImageLoader imageLoader;
public ToDoListAdapter(Context a, List<String> n,List<String> fid) {
activity = a;
content=n;
status=fid;
inflater = (LayoutInflater)activity.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Create ImageLoader object to download and show image in list
// Call ImageLoader constructor to initialize FileCache
imageLoader = new ImageLoader(activity.getApplicationContext(),"p");
}
public int getCount() {
return content.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
/********* Create a holder Class to contain inflated xml file elements *********/
class ViewHolder{
public EditText text;
}
@Override
public int getViewTypeCount() {
if (getCount() != 0)
return getCount();
return 1;
}
// @Override
// public int getViewTypeCount() {
//
// return getCount();
// }
public View getView(final int position, View convertView, ViewGroup parent) {
View vi=convertView;
final ViewHolder holder;
if(convertView==null){
/****** Inflate tabitem.xml file for each row ( Defined below ) *******/
vi = inflater.inflate(R.layout.todolistview_row, null);
/****** View Holder Object to contain tabitem.xml file elements ******/
holder = new ViewHolder();
holder.text = (EditText) vi.findViewById(R.id.listcontent);
/************ Set holder with LayoutInflater ************/
vi.setTag( holder );
}
else
holder=(ViewHolder)vi.getTag();
holder.text.setText(content.get(position));
holder.text.setTypeface(todofont);
holder.text.setSelection(holder.text.getText().length());
//
//
final Typeface font = Typeface.createFromAsset(vi.getContext().getAssets(),"fonts/MAXWELL REGULAR.ttf");
// holder.text.setTypeface(font);
if(status.get(position).equals("1"))
{
holder.text.setBackgroundColor(Color.parseColor("#0b9a0a"));
holder.text.setPaintFlags(holder.text.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
if(status.get(position).equals("0"))
{
holder.text.setBackgroundColor(Color.parseColor("#fa2007"));
}
holder.text.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
showdialog(holder.text,"edittext","yes",position);
// Toast.makeText(getBaseContext(), Status.get(position),Toast.LENGTH_LONG).show();
return false;
}
});
holder.text.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
//k=0;
if(keyCode == 66)
{
String task=holder.text.getText().toString().replace("\n","");
k++;
if(k>1)
{
content.set(position, holder.text.getText().toString().replace("\n",""));
Status.add(position,"0");
//ids.add(position,ids.get(position));
//content.add(0,additem.getText().toString());
//Status.add(0,"0");
adapter.notifyDataSetChanged();
// additem.setText("");
// additem.setVisibility(View.GONE);
db.openDataBase();
db.update_table("todolist","Task", task,"_id",ids.get(position),"","");
db.close();
k=0;
hideSoftKeyboard();
}
else
{
}
//Toast.makeText(getBaseContext(), "Enter Clicked",Toast.LENGTH_LONG).show();
}
return false;
}
});
根据从数据库返回并添加到ArrayList 状态的状态值,该任务被视为已完成或待处理。如果完成,则edittext显示为绿色,显示,否则edittext将显示为红色。
出现问题的是,在滚动列表视图时,所有的edittex都正在通过,请问有什么帮助吗?
答案 0 :(得分:2)
您需要纠正getView
部分
首先使用此
//Remove View vi=convertView;
convertView=null;
if(convertView==null)
{
// Do your staff
}