嗨我在我的应用程序中是android的新手我使用Custom Adapter类创建了一个ListView。
在ListView页脚中,我添加了两个按钮,如下图所示,当我点击ADDNEW按钮时,我想找到ListView丢失的项目位置。
public class ListViewAdapter extends ArrayAdapter<Friend> {
ViewHolder holder;
private List<Friend> myFriends;
private Activity activity;
public ListViewAdapter(Activity context, int resource, List<Friend> objects) {
super(context, resource, objects);
this.activity = context;
this.myFriends = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// If holder not exist then locate all view from UI file.
if (convertView == null) {
// inflate UI from XML file
convertView = inflater.inflate(R.layout.item_listview, parent, false);
// get all UI view
holder = new ViewHolder(convertView);
// set tag for holder
convertView.setTag(holder);
} else {
// if holder created, get tag from view
holder = (ViewHolder) convertView.getTag();
}
holder.goButton.setTag(position);
holder.binNumberEditText.setText(getItem(position).getBinNumberEditText());
holder.qtyEditText.setText(getItem(position).getQtyEditText());
holder.goButton.setOnClickListener(onConfirmListener());
return convertView;
}
public void adding(String result){
int position = ListViewadapter.getPosition();
if (position != null && !position.isEmpty() && !position.equals("null")){
myFriends.add(new Friend("", ""));
notifyDataSetChanged();
}else{
System.out.println("Yes there is null value");
}
}
答案 0 :(得分:1)
public Friend getLastFriend(){
return myFriend.get(myFriend.size() - 1);
}
告诉我你是否这样做。