【发布时间】:2016-05-10 00:53:09
【问题描述】:
首先,请原谅我蹩脚的英语。
我想知道当数据来自其他类时如何使用列表视图中的删除按钮删除项目。
我在 MainActivity 中使用了一个按钮,它将一些数据插入到称为昵称的数组中。
这是我的 CustomAdapter 类。
public class CustomAdapter extends ArrayAdapter<String>{
public CustomAdapter(Context context, String[] name) {
super(context,R.layout.custom_row ,name);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
final View customView = inflater.inflate(R.layout.custom_row, parent, false);
final String singleName = getItem(position);
TextView nickname = (TextView) customView.findViewById(R.id.nickname);
nickname.setText(singleName);
return customView;
}}
这是我在 MainActivity 类中的 onClick
public void resultNickname(View view){
nicknames[] = dbHandler.retrieveName();
setContentView(R.layout.nickname_list);
ListAdapter listAdapter = new CustomAdapter(this,nicknames);
ListView nameListView = (ListView) findViewById(R.id.nickList);
nameListView.setAdapter(listAdapter);
}
我认为我的问题可以根据这个问题的答案来解决。 android: how to delete a row from a ListView with a delete button in the row 但我无法让它工作,因为我不明白该项目的含义以及如何在我的代码中实现它。
有人可以帮我至少解释一下其他问题的含义以及如何在我的代码中实现它吗?
【问题讨论】: