Edittext不在自定义列表视图中显示数据类型

时间:2015-08-19 12:35:34

标签: android android-listview android-edittext textwatcher listview-adapter

我有一个带有edittext的自定义列表视图。我正在使用textwatcher并尝试在edittext中的texted类型大于零时添加新行。

但无论我输入什么,它都不会显示在我的编辑文本中。

enter image description here

public View getView(int position,View view,ViewGroup parent) {
        final int c = position;
        LayoutInflater inflater=context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.mylist, null,true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.Itemname);
        final EditText edittext = (EditText) rowView.findViewById(R.id.edit_text);
        Button delbtn = (Button) rowView.findViewById(R.id.delbutn);
    txtTitle.setText(itemname.get(position));
     edittext.addTextChangedListener(new TextWatcher() {
            @Override
            public void afterTextChanged(Editable s) 
            {
             String txt = edittext.getText().toString();
             if(txt.length()>0)
             {
                 if(!txt.equals("0"))
                 {
                     Log.e("test", txt);
                MainActivity.itemname.add("new"); 
                // itemname.add("new");
                    MainActivity.adapter.notifyDataSetChanged();
                    // MainActivity.adapter.insert("", 0);

                 }

             } 
            }

            @Override    
            public void beforeTextChanged(CharSequence s, int start,
              int count, int after) 
            {

            }

            @Override    
            public void onTextChanged(CharSequence s, int start,
              int before, int count) {

            }
           });
        return rowView;

}

2 个答案:

答案 0 :(得分:0)

取代

View rowView=inflater.inflate(R.layout.mylist, null,true);

使用此

convertView = inflater.inflate(R.layout.agent_details_list, parent, false);

答案 1 :(得分:0)

私密上下文活动;

然后打电话给你   this.activity =活动;

 LayoutInflater inflater=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

 view = inflater.from(activity).inflate(R.layout.agent_details_list, null);

尝试这种方式。我希望它会帮助你