【发布时间】:2016-09-03 13:51:39
【问题描述】:
我正在尝试将我的应用程序转换为 android 版本,我对 android 有点陌生。我有一个列表视图,其中的项目包括按钮。它是一个用户列表,您可以关注每个用户,当单击按钮时,只有在包含按钮的项目中,按钮文本才应变为“已关注”。检索列表工作正常,但我下面的代码按钮文本没有改变。我怎样才能做到这一点?非常感谢。
private class MyListAdapter extends ArrayAdapter<String> {
public MyListAdapter() {
super(getActivity().getApplicationContext(), R.layout.fragment_users_cell, myItemList);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View cellView = convertView;
if (cellView == null){
cellView = getActivity().getLayoutInflater().inflate(R.layout.fragment_users_cell, parent, false);
}
profileBtn = (Button) cellView.findViewById(R.id.fragment_users_cell_profileBtn);
followBtn = (Button) cellView.findViewById(R.id.fragment_users_cell_followBtn);
profileBtn.setText(myItemList.get(position));
profileBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(myItemList.get(position));
System.out.println(position);
}
});
followBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(myItemList.get(position));
profileBtn.setText("followed");
}
});
return cellView;
}
}
【问题讨论】:
-
您需要将该信息(按钮的状态)保存在传递给列表视图的列表项中
-
你好约瑟夫,我该怎么做?你能帮我做个样品吗?
标签: android listview button dynamic-tables