android列表 添加按钮,Android – 点击按钮,将项目添加到自定义列表视图

我目前有一个自定义列表视图,其中列表中的每个项目包含两行文本.我想要做的是每次用户点击按钮时,它会在列表中创建一个新项目,其中包含用户输入的文本.虽然我知道如何获取文本,但我无法在列表视图中添加新项目,因为我根本不知道从哪里开始.

这是我的代码:

public class MainFeedActivity extends ListActivity implements OnClickListener {

View sendButton;

EditText postTextField;

TextView currentTimeTextView, mainPostTextView;

ListView feedListView;

String[] test;

ArrayList> list;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main_feed);

//create button and implement on click listener

sendButton = this.findViewById(R.id.sendPostButton);

sendButton.setOnClickListener(this);

list = new ArrayList>();

//create the adapter for the list view

SimpleAdapter adapter = new SimpleAdapter(

this,

list,

R.layout.post_layout,

new String[]{"time", "post"},

new int[]{R.id.postTimeTextView, R.id.postTextView});

//fill the list view with something - TEST

fillData();

//set list adapter

setListAdapter(adapter);

}

public void fillData() {

//long timeTest = System.currentTimeMillis();

HashMap temp = new HashMap();

temp.put("time", "current time");

temp.put("post", "USER TEXT GOES HERE");

list.add(temp);

}

@Override

public void onClick(View button) {

switch (button.getId()) {

case R.id.sendPostButton:

break;

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值