1
我正在創建一個使用齊射的自定義列表視圖feed。Android自定義列表視圖,不能更改單個行中的元素
listview是在Fragment上,我使用customListAdapter.java和SearchItem.java類將內容加載到列表視圖。
問題是,當我點擊一行按鈕或保存按鈕時,它不僅在該行而且在其他一些行中更改爲喜歡並保存。
在我的片段
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);
在onItemClick片段
的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();
}
你是什麼意思的豆類? –
看看這裏... http://www.javatpoint.com/java-bean –
我已經有了這個類,它用來創建一個對象和設置值,但是如何存儲用戶狀態?公共類搜索項{ \t public String txt_title, \t公共SearchItem(){ \t} \t公共SearchItem(字符串txt_username,字符串txt_title,字符串post_type_img){ \t \t this.txt_username = txt_username; \t \t this.txt_title = txt_title; \t \t this.post_type_img = post_type_img; \t} \t public int getpostid(){ \t \t return postid; \t} \t公共無效setpostid(INT帖子ID){ \t \t this.postid =帖子ID; \t} } –