我有一个保存按钮:
public void saveEvent(View view) {
Intent intent = new Intent(this, SaveEvent.class);
startActivity(intent);
}
按下它时,我希望它将EditText输入添加到Listview。顺便说一句,Listview和EditText + Save Button元素位于不同的XML布局上。
我有一个名为SaveEvent的活动,当按下Save按钮时会发生这种活动。如何将EditText输入添加到ListView元素?
非常感谢你。
一块MakeEvent.java:
package com.kass.planner;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
public class SaveEvent extends Activity implements View.OnClickListener{
private Button btn;
private EditText et;
private ListView lv;
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.save);
btn.setOnClickListener(this);
et = (EditText) findViewById(R.id.editText);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, list);
// set the lv variable to your list in the xml
lv = (ListView) findViewById(R.id.event_list);
lv.setAdapter(adapter);
}
public void onClick(View v) {
String input = et.getText().toString();
if (input.length() > 0) {
// add string to the adapter, not the listview
adapter.add(input);
// no need to call adapter.notifyDataSetChanged(); as it is done by the adapter.add() method
}
}
SaveEvent.java:
// Get namespace URI for prefix `itunes`
echo $ns = $s->lookupNamespaceURI('itunes');
// Get `image` tag from that namespace
echo $href = $node->getElementsByTagNameNS($ns, 'image')->item(0)->getAttribute('href');
但是这段代码不起作用...... ^谢谢。
答案 0 :(得分:-2)
在板球家的启示下,重新审视我的一些旧程序 而不是更新适配器对象
仅更新下划线数据 并调用以下方法以使用更新的适配器对象
绑定列表视图对象public void fillList() {
ArrayAdapter<String> adapter= new ArrayAdapter<>(context,android.R.layout.simple_list_item_1,getItems());
lv.setAdapter(adapter);
}
我同意。没有记忆效率但效果很好