0

我有一个现有用户的 ListviewEditText和 TextViews。我正在使用 EditText 添加新用户。输入名称后如何通过 EditText 添加新用户?结果应该出现在 ListView 中,如下所示![在此处输入图像描述][1]。

 @Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    ViewHolder holder;
    if(convertView==null)
    {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.savelistviewadapter, null);

        holder.username = (TextView)convertView.findViewById(R.id.username);
        holder.newuser = (EditText) convertView.findViewById(R.id.newuser);
        holder.radiosave = (RadioButton) convertView.findViewById(R.id.radiosaveuser);
       // holder.img = (ImageView)  convertView.findViewById(R.id.temperrr);

        convertView.setTag(holder);
    }
    else
    holder=(ViewHolder)convertView.getTag();

    ItemBean bean = (ItemBean) itemList.get(position);

   // holder.imgViewLogo.setBackgroundResource(bean.getImage());
    holder.username.setText(bean.getTitle());
    if(holder.newuser.getText().toString().length()>0)
    {
    holder.username.setText(holder.newuser.getText().toString());
    }
   // holder.txtViewDescription.setText(bean.getDescription());
   // holder.img.setImageResource(R.drawable.ic_download);
   if(position==getCount()-1)
   {
       holder.newuser.setVisibility(View.VISIBLE); 
   }
   else
   {
       holder.newuser.setVisibility(View.GONE); 
   }
    return convertView;
}

}
4

1 回答 1

0
ListView mListView;
EditText mValue;
Button mAdd;

List<String> data = new ArrayList<String>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_listview);

    data.add("Hello World");

    mListView = (ListView) findViewById(R.id.custom_list);
    mValue = (EditText) findViewById(R.id.text_to_add);
    mAdd = (Button) findViewById(R.id.add_string);

    mListView.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, data));
    mAdd.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View currentView) {
            data.add(new String(mValue.getText().toString()));
        }
    });
}
于 2013-06-07T10:12:01.620 回答