💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
#ListView 与 BaseAdapter 在一个界面上,展示一连串相似的信息 ~~~ main.xml 资源文件 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fragment_my_library" android:background="@color/colorGhostWhite"> <ListView android:id="@+id/fragment_my_library_listview" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" ></ListView> </LinearLayout> MainActivtiy.java 逻辑文件 import android.graphics.Color; import android.os.Bundle; import android.support.annotation.Nullable; import android.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; import com.suityou.www.suityou.R; public class MyLibraryFragment extends Fragment { //展示书籍的组件 private ListView showBooksListView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } //设置监听器 private void listeners() { showBooksListView.setAdapter(new BooksListViewAsapter()); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View messageLayout = inflater.inflate(R.layout.fragment_my_library, container, false); TextView textView=(TextView) messageLayout.findViewById(R.id.fragment_my_library_textview); textView.setText("我的书籍"); //初始化组件 init(messageLayout); //设置监听器 listeners(); return messageLayout; } //初始化组件 private void init(View view) { showBooksListView = (ListView) view.findViewById(R.id.fragment_my_library_listview); } private class BooksListViewAsapter extends BaseAdapter { //列表的数量 @Override public int getCount() { return 10; } @Override public Object getItem(int ItemNumber) { return ItemNumber; } @Override public long getItemId(int ItemIdNumber) { return ItemIdNumber; } @Override public View getView(int i, View view, ViewGroup viewGroup) { TextView textView=new TextView(getContext()); textView.setText("你吃白饭没"); textView.setTextColor(Color.RED); return textView; } } } ~~~