In my listview's item, there is a two components.
<TextView
android:id="@+id/owner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="방장"
android:layout_centerInParent="true"
android:textColor="@color/colorBlack"
android:textSize="10dp"/>
<ImageButton
android:id="@+id/kickOutBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:visibility="invisible"
android:scaleType="fitCenter"
android:background="@color/colorTransparent"
android:tint="@color/colorBlack"
android:src="@drawable/ic_baseline_close_24"/>
These are in a same location in a view.
I mean, the Textview is located in the center of the ImageButton.
And if the ListView item's target is a manager, I want to make its list item's ImageButton invisible and open the Textview that says manager, and if not, I want to make its list item's ImageButton show the opposite, and I want to make the Textview that says manager invisible. (default is that imagebutton is invisible and textview is visible)
To do that, I tried to this code.
// getView in ListAdapter
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
View view;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.navi_list_menu_item, null);
}
else {
view = convertView;
}
TextView supervisor_tv = (TextView) view.findViewById(R.id.owner);
ImageButton kick_btn = (ImageButton) view.findViewById(R.id.kickOutBtn);
if(!mNavItems.get(i).fb_uid.equals(roomSupervisor)) {
kick_btn.setVisibility(View.VISIBLE);
kick_btn.setOnClickListener(v -> {
Log.d("ChatRoomActivity", "click imagebutton");
});
supervisor_tv.setVisibility(View.INVISIBLE);
}
return view;
}
// Activity
mDrawerList = (ListView) findViewById(R.id.nav_list);
mDrawerList.addHeaderView(listHeaderView);
NaviDrawerListAdapter adapter = new NaviDrawerListAdapter(this, mNavItems, roomSupervisor);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener((adapterView, view, position, id) -> {
Log.d(TAG, String.valueOf(position));
});
It is ok to click manager's list item and ImageButton of others.
But the problem is that I cannot click non-manager user's list item.
Could you tell me what is the problem of my code?