【问题标题】:Edittext not displaying data type in custom listviewEdittext不在自定义列表视图中显示数据类型
【发布时间】:2015-08-19 12:35:33
【问题描述】:

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

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

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;

}

【问题讨论】:

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


    【解决方案1】:

    代替

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

    使用这个

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      相关资源
      最近更新 更多