我有一个带有EditText
的Listview和现有用户的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;
}
}
答案 0 :(得分: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()));
}
});
}