I try to edit data in custom list view by click button. Inside Listener i edit data in this line
data.get(position).setName("data");
Data is edited but i see changes when i move my listview with edited data out of window bounds and when i move back then i see changes. My target is to see changes in this time when i click the button. How to do this?? In ListView in each row i have 3 textview and 1 button which i want to edit textview.
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
public class UserCustomAdapter extends ArrayAdapter<User> {
int layoutResourceId;
ArrayList<User> data = new ArrayList<User>();
private DataSource datasource;
private Context context;
private Comment comment;
private String[] dane;
private UserHolder holder;
private User user;
public UserCustomAdapter(Context context, int layoutResourceId,
ArrayList<User> data) {super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.textName = (TextView) row.findViewById(R.id.textView1);
holder.textPrice = (TextView) row.findViewById(R.id.textView2);
holder.textAttribute = (TextView) row.findViewById(R.id.textView3);
holder.btnEdit = (Button) row.findViewById(R.id.button1);
row.setTag(holder);
} else {
holder = (UserHolder) row.getTag();
}
user = data.get(position);
holder.textName.setText(user.getName());
holder.textPrice.setText(user.getPrice());
holder.textAttribute.setText(user.getAttribute());
holder.btnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
/* datasource = new DataSource(getContext());
datasource.open();
comment = datasource.getComment("1");
dane = comment.toString().split(" ");
*/
data.get(position).setName("data");
System.out.println(position);
}
});
return row;
}
static class UserHolder {
TextView textName;
TextView textPrice;
TextView textAttribute;
Button btnEdit;
}
}
更新后使用notifyDataSetChanged方法
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.