我想使用此方法为我的List创建一个“ADD String”按钮,该按钮通过字符串数组运行。
这只是一次练习,我似乎无法做到这一点。
我的目标是在列表中添加一个项目,单击该项目。将提示用户将另一个String添加到列表中,但是我似乎无法添加页脚。我能用什么?
MainActivity中的onCreate()方法@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Show array
String favTVShows[] = {"Naruto", "One Piece", "Kuroko no Basket", "Tokyo Ghoul", "Parasyte - the maxim -", "Nanatsu no Taizai"};
ListAdapter theAdapter = new MyAdapter(this, favTVShows);
//Add xml a ListView e set o MyAdapter.class
ListView theListView = (ListView) findViewById(R.id.listView1);
View v = getLayoutInflater().inflate(R.layout.extras, null);
theListView.addFooterView(v);
theListView.setAdapter(theAdapter);
//Quando CLICK num item da toast.
theListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
String tvShowPicked = "You selected " + String.valueOf(adapterView.getItemAtPosition(position));
Toast.makeText(MainActivity.this, tvShowPicked, Toast.LENGTH_SHORT).show();
}
});
}
编辑:无法发布图片,但现在就是它的显示方式。 http://puu.sh/g42zV/5e451eeeae.jpg