J'essaie d'extraire un textView dans un adaptateur personnalisé, mais il renvoie null pour une raison quelconque. Pouvez-vous expliquer pourquoi? Je suis nouveau sur Android et je suis coincé ici. Je joins également la vue à laquelle l'adaptateur se connecte, son profile_listitem.xml et contient le textView que je veux.findViewbyId dans l'adaptateur personnalisé renvoie null
Merci
AdapterProfile.xml
public AdapterProfiles(Context context,ArrayList<Profile> profilesArray)
{
super(context, R.layout.profile_listitem, profilesArray);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Profile p= getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.profile_listitem , parent, false);
}
TextView textAppName=(TextView)convertView.findViewById(R.id.textViewApp);
ToggleButton appStatus =(ToggleButton)convertView.findViewById(R.id.toggleAppStatus);
if(convertView.findViewById(R.id.textViewApp)==null)
Log.d("Profile","Profile is null");
textAppName.setText(p.getName());
appStatus.setChecked(p.isActive());
return convertView;
}
profile_listitem.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@color/background"
android:textColor="@color/blue"
android:textSize="36dp"
android:id="@+id/textViewAppName"/>
<ToggleButton
android:layout_width="72dp"
android:layout_height="48dp"
android:layout_alignParentEnd="true"
android:textColor="@color/white"
android:background="@color/blue"
android:id="@+id/toggleAppStatus"/>