【发布时间】:2016-08-31 12:11:33
【问题描述】:
我是 Android 新手,将布尔标志发送到扩展 ArrayAdapter 的自定义 ListView 类时遇到问题... 我的代码:
public class FriendListView extends ArrayAdapter {
private final Activity context;
private final ArrayList<String> photo_url;
private final ArrayList<String> friend_name;
private final ArrayList<String> id;
private final Boolean online;
public FriendListView(Activity context, ArrayList<String> photo_url, ArrayList<String> friend_name, ArrayList<String> id, Boolean online) {
super(context, R.layout.friend_view, friend_name);
this.context = context;
this.photo_url = photo_url;
this.friend_name = friend_name;
this.id = id;
this.online = online;
Log.d("VK_LIST_VIEW", "online => " + online); //here is normall pass
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.friend_view, null, true);
Log.d("VK_POSITION_INDEX", photo_url.get(position));
TextView txt_friend = (TextView) rowView.findViewById(R.id.txt_friend);
Log.d("VK_LIST_VIEW_2", "online => " + online); //here I can't acces passed value
//on friend selecting
txt_friend.setOnClickListener(new View.OnClickListener() {@Override
public void onClick(View view) {
Log.d("VK_", "friend selected => " + friend_name.get(position) + " id => " + id.get(position) + " is online => " + online);
}
});
txt_friend.setText(friend_name.get(position));
//show image from url into ImageView
Picasso.with(context).load(photo_url.get(position)).transform(new CircleTransform()).into((ImageView) rowView.findViewById(R.id.img_photo));
return rowView;
}
}
我正在使用第二个代码从另一个类传递online 标志:
adapter = new FriendListView(Logged.this, photo_url, friendArray, friend_id, online);
那么当我将它传递给 arrayadapter 时,我如何获得在线标志(即 online = true,然后我在适配器中得到 true)?现在不是这样了......
谁能帮忙解决?
【问题讨论】:
-
描述你的
problem? -
当您说“我无法访问传递的值”时,您是什么意思?编译器会抛出错误吗?还是值变了?
-
@Abbas 不,编译器不会抛出任何错误,
Log.d("VK_LIST_VIEW_2", "online => " + online);中的值始终为 false -
@vladimir 添加完整的类代码。
-
确保你的在线没有在你的适配器类中声明为 final
标签: java android listview android-arrayadapter android-custom-view