如何仅为授权用户在listview中显示隐藏按钮?

时间:2016-08-23 20:56:36

标签: android listview adapter

当授权人进入观看组列表时,列表视图不包含删除选项,但如果avalide人观看组列表,listview将包含删除按钮(如facebook组,admin将显示一些额外选项但成员不会)

这是我的代码

MemberActivity.java

public class MemberActivity extends AppCompatActivity {


private ListView memberListListView;

private String userIdString;
private String groupIdString;
private String groupNameString;
private String universityNameString;
MemberListAdapter memberListAdapter;


private SQLiteHandler db;
ArrayList<MemberLisModel> memberList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_member);

    memberListListView= (ListView) findViewById(R.id.memberListLV);

    userIdString = getIntent().getStringExtra("UserId");
    groupIdString = getIntent().getStringExtra("GroupId");
    groupNameString = getIntent().getStringExtra("GroupName");
    universityNameString = getIntent().getStringExtra("UniversityName");



    db=new SQLiteHandler(getApplicationContext());
    memberList=db.getMemberListFromGroupMemberList(groupIdString);
    if(memberList.size()!=0 && memberList.size()>0) {
        final MemberListAdapter memberListAdapter = new MemberListAdapter(getApplicationContext(), 0, memberList);
        memberListListView.setAdapter(memberListAdapter);
    }

    boolean cr=db.chechCrStatus(userIdString,groupIdString);


}

}

MemberListAdapter.java

public class MemberListAdapter extends ArrayAdapter<MemberLisModel> {

TextView memberName;
TextView joiningDate;
TextView crIdentification;
public Button memberDeleteButton;


public MemberListAdapter(Context context, int resource, List<MemberLisModel> objects) {
    super(context, 0,objects);
}

@Override
public View getView(int position, View convertView, ViewGroup parent){
    MemberLisModel memberLisModel=getItem(position);
    if (convertView==null){
        convertView= LayoutInflater.from(getContext()).inflate(R.layout.single_member_view,parent,false);
    }
    memberName= (TextView) convertView.findViewById(R.id.meberNameTV);
    joiningDate = (TextView) convertView.findViewById(R.id.memberJoiningDateTV);
    crIdentification= (TextView) convertView.findViewById(R.id.crIdentificationTV);
    memberDeleteButton= (Button) convertView.findViewById(R.id.memberDeleteBtn);

    String memberStatus=memberLisModel.getMemberStatus();

    if (memberStatus.toLowerCase().equals("true")){
        crIdentification.setVisibility(View.VISIBLE);
    }

    memberName.setText(memberLisModel.getMemberName());
    joiningDate.setText(memberLisModel.getMemberListCreatedAt());

    return  convertView;
}

}

1 个答案:

答案 0 :(得分:0)

我不知道问题出在哪里?

您在适配器中获得了代码 -

  if (memberStatus.toLowerCase().equals("true")) // is admin ?
  {   
        crIdentification.setVisibility(View.VISIBLE);
        memberDeleteButton.setVisibility(View.VISIBLE);
  }
  else
  {
        memberDeleteButton.setVisibility(View.INVISIBLE);
  }