0
カスタムアダプタでtextViewを取得しようとしていますが、何らかの理由でnullが返されています。あなたは理由を説明できますか? Androidに新しくて、ここにこだわっています。私は、アダプタが接続しているビューprofile_listitem.xmlを添付しています。必要なtextViewが含まれています。 カスタムアダプタのfindViewbyIdがnullを返す
は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"/>