我有编辑文字& listview在布局中,我想要在编辑文本文本更改事件上添加listview项目值。假设我开始输入编辑文本,该字符将在列表视图中显示为列表项。
我怎么能实现那个......?
我的基本适配器getView()代码如下。我正在以编程方式创建文本视图,
TTDemo msg = (TTDemo) this.getItem(position);
ViewHolder viewHolder = null;
if(convertView == null)
{
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(context).inflate(R.layout.row, group, false);
viewHolder.relativeLayout = (RelativeLayout) convertView.findViewById(R.id.root_rl);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);;
rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
rlp.setMargins(0, 8, 0, 8);
bg = new TextView(context);
bg.setGravity(Gravity.CENTER);
bg.setPadding(2, 2, 2, 2);
bg.setTextSize(20f);
bg.setTextColor(Color.RED);
bg.setBackgroundColor(Color.RED);
bg.setLayoutParams(rlp);
viewHolder.relativeLayout.addView(bg);
textView = new TextView(context);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(20f);
textView.setTextColor(Color.WHITE);
textView.setBackgroundColor(Color.TRANSPARENT);
textView.setLayoutParams(rlp);
viewHolder.relativeLayout.addView(textView);
Animation animation = AnimationUtils.loadAnimation(context, R.anim.zoom_out);
bg.setAnimation(animation);
viewHolder.message = msg;
convertView.setTag(viewHolder);
}
else
viewHolder = (ViewHolder) convertView.getTag();
if(msg.getName() != null)
{
bg.setText("." + msg.getName() + ".");
textView.setText("" + msg.getName());
}
else
{
viewHolder = null;
}
return viewHolder.relativeLayout;
关于EditTexts文本更改事件,
et.addTextChangedListener(new new TextWatcher()
{
@Override
public void onTextChanged(CharSequence sequence, int start, int before, int count)
{
if(sequence != null && sequence.length() > 0)
{
list.add(al);
adapter.notifyDataSetChanged();
listView.setSelection(list.size()-1);
}
}
});
Model Class,al是此类的一个实例(textChange方法中的list.add(al))
public class TTDemo
{
public String name;
public int isFinished;
public TTDemo(String name, int isFinished)
{
this.name = name;
this.isFinished = isFinished;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
答案 0 :(得分:0)
如果我正确理解了这个问题,那么您尝试过滤listView。 如果是这样,请将EditText字段添加到布局中,并将 OnTextChangeListener 添加到EditText字段,并在其回调方法中将过滤器应用于listview的适配器。请记住,如果要过滤自定义BaseAdapter,请确保为Custom BaseAdapter实现可过滤的界面。
有关其他信息,请参阅this问题。