Android自定义Listview,无法更改单行中的元素
我正在使用截击创建一个类似facebook的自定义listview提要 listview位于片段上,我使用customListAdapter.java和SearchItem.java类将内容加载到listview 问题是,当我在一行中单击“喜欢”按钮或“保存”按钮时,它不仅会在该行中更改为“喜欢”,而且还会在其他一些行中更改为“保存” 在我的片段中Android自定义Listview,无法更改单行中的元素,android,listview,android-listview,Android,Listview,Android Listview,我正在使用截击创建一个类似facebook的自定义listview提要 listview位于片段上,我使用customListAdapter.java和SearchItem.java类将内容加载到listview 问题是,当我在一行中单击“喜欢”按钮或“保存”按钮时,它不仅会在该行中更改为“喜欢”,而且还会在其他一些行中更改为“保存” 在我的片段中 final ViewHolder holder = new ViewHolder(); @Override public View on
final ViewHolder holder = new ViewHolder();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.newsfeed_popular_frag, container, false);
listView = (ListView) v.findViewById(R.id.popular_list);
adapter = new CustomListAdapter(getActivity(), PopularList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
在一片碎片中
holder.likes_layout = (LinearLayout) parent.findViewById(R.id.likes_layout);
holder.saves_layout = (LinearLayout) parent.findViewById(R.id.saves_layout);
holder.likes_layout.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
put_like();
}
});
在customListAdapter中
public View getView(int position, View convertView, ViewGroup parent) {
//post_id,name,user_prof_pic,post_description,post_datetime
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
if (convertView == null){
convertView = inflater.inflate(R.layout.newsfeed_list_row, null);
holder = new ViewHolder();
holder.comment_layout = (LinearLayout) parent.findViewById(R.id.comment_layout);
holder.likes_layout = (LinearLayout) parent.findViewById(R.id.likes_layout);
holder.saves_layout = (LinearLayout) parent.findViewById(R.id.saves_layout);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
请提供您的代码的更多详细信息,以获得正确答案。 但正如我在这里看到的 holder.likes\u layout.setOnClickListener(新的OnClickListener(){ 公共void onClick(视图v){
您没有在代码中存储用户状态。因此我建议为此使用bean类请提供代码的更多详细信息,以获得正确答案。 但正如我在这里看到的 holder.likes\u layout.setOnClickListener(新的OnClickListener(){ 公共void onClick(视图v){
您没有在代码中存储用户状态。因此,我可以建议为此使用bean类bean类是什么意思?我已经有了该类,它用于创建对象和设置值,但如何存储用户状态?公共类SearchItem{public String txt_title,txt_username,post_type_img,user_photo,txt_days,post_type;public SearchItem(){}public SearchItem(String txt_username,String txt_title,String post_type_img){this.txt_username=txt_username;this.txt_title=txt_title;this.post_type_img=post_type_title=post_type_img;}public int getpostd(){return postid;}public void setpostid(int postid){this.postid=postid;}}}bean类是什么意思?我已经有了这个类,它用来创建一个对象和设置值,但是如何存储用户状态?public class SearchItem{public String txt_title,txt_username,post_type_img,user_photo,txt_days,post_type;public SearchItem(){}public SearchItem(String txt_username,String txt_title,String post_type_img){this.txt_username=txt_username;this.txt_title=txt_title;this.post_type_img=post_type_title=post_type_img;}public int getpostd(){return postid;}public void setpostid(int postid){this.postid=postid;}}}bean类是什么意思?我已经有了这个类,它用来创建一个对象和设置值,但是如何存储用户状态?public class SearchItem{public String txt_title,txt_username,post_type_img,user_photo,txt_days,post_type;public SearchItem(){}public SearchItem(String txt_username,String txt_title,String post_type_img){this.txt_username=txt_username;this.txt_title=txt_title;this.post_type_img=post_type_title=post_type_img;}public int getpostd(){return postid;}public void setpostid(int postid){this.postid=postid;}
put_like();
}
});