在视图中填充线性布局,无法在 android 的文本框中显示值

populating a linear layout in a view, not able to show the values in the textboxes in android

我在 activity 中拥有所有内容,但适配器出现问题,因此数据未显示在 linearlayouttextviews 中。我正在使用 ListView 来显示 LinearLayout 视图。 这里是my DetailsAdapter.java

public class DetailsAdapter extends BaseAdapter {
private Context context;
private Activity activity;
private LayoutInflater inflater;
private ArrayList<Details> detailsList;
public DetailsAdapter(Context context, ArrayList<Details> detailsList) {
    this.context=context;
    inflater = LayoutInflater.from(context);
    this.detailsList = detailsList;
}

@Override
public int getCount() {
    return detailsList.size();
}

@Override
public Object getItem(int i) {
    return detailsList.get(i);
}

@Override
public long getItemId(int i) {
    return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    if(view == null) {
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.place_details_single,null);
    }
    TextView Name = view.findViewById(R.id.d_name);
    Name.setText(detailsList.get(i).getDname());
    TextView Rating = view.findViewById(R.id.d_rating);
    Rating.setText(detailsList.get(i).getDrating());
    TextView Address = view.findViewById(R.id.d_address);
    Address.setText(detailsList.get(i).getDaddress());
    TextView Phone = view.findViewById(R.id.d_phone);
    Phone.setText(detailsList.get(i).getDphone());
    Button beenthere = view.findViewById(R.id.btn_beenthere);
    beenthere.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    Button viewOnMap = view.findViewById(R.id.btn_view_on_map);
    viewOnMap.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    Button restaurants = view.findViewById(R.id.btn_restaurants);
    restaurants.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    Button hotels = view.findViewById(R.id.btn_hotels);
    hotels.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    return view;
}

这是执行停止的日志文件

04-26 23:41:12.595 11563-11712/com.wanderalchemy.testgrid D/NativeCrypto: ssl=0xa919a500 sslRead buf=0x9d6db800 len=2048,timeo=20000
04-26 23:41:12.595 11563-11713/com.wanderalchemy.testgrid I/System.out: [OkHttp] sendRequest<<
04-26 23:41:12.595 11563-11713/com.wanderalchemy.testgrid D/NativeCrypto: ssl=0xaf338600 sslWrite buf=0x9d73f800 len=447 write_timeout_millis=0
04-26 23:41:12.596 11563-11713/com.wanderalchemy.testgrid D/NativeCrypto: ssl=0xaf338600 sslRead buf=0x9d73f800 len=2048,timeo=20000
04-26 23:41:12.679 11563-11590/com.wanderalchemy.testgrid D/OpenGLRenderer: CacheTexture 3 upload: x, y, width height = 0, 0, 129, 495
04-26 23:41:12.697 11563-11590/com.wanderalchemy.testgrid I/[MALI][Gralloc]: [+]r_hnd(0x9d695b80), client(27), share_fd(66)
04-26 23:41:12.697 11563-11590/com.wanderalchemy.testgrid D/GraphicBuffer: register, handle(0x9d695b80) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
04-26 23:41:12.706 11563-11563/com.wanderalchemy.testgrid V/InputMethodManager: START INPUT: android.widget.ListView{7b90042 VFED.VC.. .F...... 0,0-720,300 #7f0d00ae app:id/Pdetailsitem} ic=null tba=android.view.inputmethod.EditorInfo@c7c2c5a controlFlags=#100
04-26 23:41:12.711 11563-11590/com.wanderalchemy.testgrid D/Surface: Surface::disconnect(this=0xaf41bb00,api=1)
04-26 23:41:12.714 11563-11590/com.wanderalchemy.testgrid D/GraphicBuffer: unregister, handle(0xb46bfa60) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
04-26 23:41:12.714 11563-11590/com.wanderalchemy.testgrid I/[MALI][Gralloc]: [-]r_hnd(0xb46bfa60), client(27), share_fd(43)
04-26 23:41:12.715 11563-11590/com.wanderalchemy.testgrid D/GraphicBuffer: unregister, handle(0xb46bfe20) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
04-26 23:41:12.716 11563-11590/com.wanderalchemy.testgrid I/[MALI][Gralloc]: [-]r_hnd(0xb46bfe20), client(27), share_fd(47)
04-26 23:41:12.716 11563-11590/com.wanderalchemy.testgrid D/GraphicBuffer: unregister, handle(0xb46bed40) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
04-26 23:41:12.718 11563-11590/com.wanderalchemy.testgrid I/[MALI][Gralloc]: [-]r_hnd(0xb46bed40), client(27), share_fd(53)
04-26 23:41:12.718 11563-11590/com.wanderalchemy.testgrid E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb46bec00
04-26 23:41:12.718 11563-11590/com.wanderalchemy.testgrid D/mali_winsys: [MALI] win=0xaf41bb08, native_buffer=0xb46be8e8, fd=-1
04-26 23:41:12.718 11563-11590/com.wanderalchemy.testgrid D/GraphicBuffer: unregister, handle(0xb46bec00) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
04-26 23:41:12.720 11563-11590/com.wanderalchemy.testgrid I/[MALI][Gralloc]: [-]r_hnd(0xb46bec00), client(27), share_fd(54)
04-26 23:41:12.720 11563-11590/com.wanderalchemy.testgrid D/Surface: Surface::disconnect(this=0xaf41bb00,api=1)
04-26 23:41:12.721 11563-11590/com.wanderalchemy.testgrid D/OpenGLRenderer: endAllActiveAnimators on 0x9e2fd780 (CardView @679ef2b) with handle 0xb460c450

我已经尝试了所有可能的方法,但无法将我从数据库中检索到的数据显示到 ListView 中。请帮忙。先感谢您 更新,我要膨胀的 xml 代码是

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="3">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">
            <TextView
                android:id="@+id/d_name"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="match_parent" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:orientation="vertical"
                android:weightSum="2">

                <TextView
                    android:id="@+id/d_rating"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />

                <ToggleButton
                    android:id="@+id/btn_beenthere"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:checked="false"
                    android:textOff="Yet to Visit"
                    android:textOn="Been there"
                    android:textSize="8sp" />

                <!--image resource needed-->
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="4">
            <Button
                android:id="@+id/btn_view_on_map"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="View on MAP" />

            <Button
                android:id="@+id/btn_restaurants"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Nearby Restaurants" />

            <Button
                android:id="@+id/btn_hotels"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:text="Nearby Hotels" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                android:id="@+id/d_address"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/d_phone"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
        </LinearLayout>
    </LinearLayout>

更改代码的这些行

if(view == null) {
    ...
    view = inflater.inflate(R.layout.place_details_single,null);
}

改成这个

if(view == null) {
    ...
    view = inflater.inflate(R.layout.place_details_single, viewGroup, false);
}

如果您在不传递父视图的情况下膨胀视图,膨胀器将不知道您的 match_parent 宽度使用什么尺寸,因此它将有效地使用 wrap_content 代替。由于根内的所有内容都是 match_parent0dp(带权重),因此此 "wrap content" 行为将为 0dp。