安卓开发感悟 — GPT使用

开发者在尝试使用Activity方法实现Fragment内的ListView适配时遇到困难,最终通过简化需求并提供基本布局给GPT,成功获取了有效代码。具体到homeFragment.java中,需要为ListView设置gonglve_list_item.xml的样式。
摘要由CSDN通过智能技术生成
  • 把要做的事情简化为最基本的一个要求,交给GPT解决,然后在基础版本上逐步实现更复杂的需求。

        任务:首页的Fragment使用适配器,每一行显示一个攻略(含图片、文字等),起初是模仿Activity调用适配器的代码,但发现这种方法不适用于Fragment(不显示列表内容),就一直把最终的复杂代码交给GPT,但一直无法解决问题。

        最终,删除所有代码,把homeFragment的布局代码和列表每一行的样式需求告诉GPT,得到了有效回答。(xml代码都是最简单的样式)

提问:

安卓开发中,homeFragment.java的布局fragment_home.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <ListView
        android:id="@+id/lve_listview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</ScrollView>
现在想要id为lve_listview的列表,每一行的样式均为gonglve_list_item.xml,gonglve_list_item.xml代码如下:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/green">

    <TextView
        android:layout_width="100dp"
        android:layout_height="30dp"
        android:text="BeiJing"
        android:textSize="19dp"
        android:translationX="70dp" />

</LinearLayout>

homeFragment.java 代码如何编写

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值