成都网站设计很好,做期货要关注哪些网站,wordpress运行速度慢,我的网站模板框架的ListFragment的静态库支持版本#xff0c;用于编写在Android 3.0之前的平台上运行的应用程序#xff0c;在Android 3.0或更高版本上运行时,仍使用此实现。 List fragment 的基本实现是用于创建fragment中的项目列表 List in Fragments
示例
本示例将向您说明如何基于…
框架的ListFragment的静态库支持版本用于编写在Android 3.0之前的平台上运行的应用程序在Android 3.0或更高版本上运行时,仍使用此实现。 List fragment 的基本实现是用于创建fragment中的项目列表 List in Fragments
示例
本示例将向您说明如何基于arrayAdapter创建自己的列表片段在开始编码之前,我将在 res/values目录下的 string.xml 文件中初始化字符串常量。
?xml version1.0 encodingutf-8?
resourcesstring nameapp_nameListFragmentDemo/stringstring nameaction_settingsSettings/stringstring namehello_worldHello world!/stringstring nameimgdescimgdesc/stringstring-array namePlanetsitemSun/itemitemMercury/itemitemVenus/itemitemEarth/itemitemMars/itemitemJupiter/itemitemSaturn/itemitemUranus/itemitemNeptune/item/string-array/resources
以下是 res/layout/activity_main.xml 文件的内容。它包含线性布局和fragment标签。
?xml version1.0 encodingutf-8?
LinearLayoutxmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical fragmentandroid:idid/fragment1android:namecom.example.learnfk7.myapplication.MyListFragmentandroid:layout_widthmatch_parentandroid:layout_heightmatch_parent //LinearLayout
以下是 res/layout/list_fragment.xml 文件的内容它包含线性布局,列表视图和文本视图
?xml version1.0 encodingutf-8?
LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:orientationvertical ListViewandroid:idandroid:id/listandroid:layout_widthmatch_parentandroid:layout_heightwrap_content /ListViewTextViewandroid:idandroid:id/emptyandroid:layout_widthmatch_parentandroid:layout_heightwrap_content /TextView
/LinearLayout
以下是 src/main/java/myListFragment.java 文件的内容在编写代码之前,需要执行以下几步操作,如下所示
创建一个类MyListFragment并将其扩展到ListFragment。在 onCreateView()方法的内部,使用上面定义的list_fragment xml布局为视图。在 onActivityCreated()方法内,从资源创建一个arrayadapter,即使用String array R.array.planet,您可以在string.xml中找到并将此适配器设置为listview并还要设置onItem点击监听器。在 OnItemClickListener()方法内部,显示一条带有被单击的商品名称的消息。
package com.example.learnfk7.myapplication;import android.annotation.SuppressLint;
import android.app.ListFragment;
import android.os.Bundle;import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Toast;public class MyListFragment extends ListFragment implements OnItemClickListener {Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {View view inflater.inflate(R.layout.list_fragment, container, false);return view;}Overridepublic void onActivityCreated(Bundle savedInstanceState) {super.onActivityCreated(savedInstanceState);ArrayAdapter adapter ArrayAdapter.createFromResource(getActivity(), R.array.Planets, android.R.layout.simple_list_item_1);setListAdapter(adapter);getListView().setOnItemClickListener(this);}Overridepublic void onItemClick(AdapterView? parent, View view, int position,long id) {Toast.makeText(getActivity(), Item: position, Toast.LENGTH_SHORT).show();}
} 以下代码将成为MainActivity.java的内容
package com.example.learnfk7.myapplication;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;public class MainActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}
}
以下代码将是manifest.xml的内容,该文件位于res/AndroidManifest.xml中
?xml version1.0 encodingutf-8?
manifest xmlns:androidhttp://schemas.android.com/apk/res/androidpackagecom.example.learnfk7.myapplicationapplicationandroid:allowBackuptrueandroid:iconmipmap/ic_launcherandroid:labelstring/app_nameandroid:supportsRtltrueandroid:themestyle/AppThemeactivity android:name.MainActivityintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER //intent-filter/activity/application
/manifest
运行应用程序
让我们尝试运行我们刚刚创建的 SimpleListFragment 应用程序。我假设您在进行环境设置时创建了 AVD ,要从Android Studio运行该应用程序,请打开您项目的Activity文件之一,然后单击运行工具栏。 Android将应用程序安装在您的AVD上并启动它,如果设置和应用程序一切正常,它将显示在Emulator窗口下方- Android 中的 List fragments函数 - 无涯教程网无涯教程网提供框架的ListFragment的静态库支持版本用于编写在Android 3.0之前的平台上运行的应用...https://www.learnfk.com/android/android-list-fragment.html 文章转载自: http://www.morning.xsjfk.cn.gov.cn.xsjfk.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.jlqn.cn.gov.cn.jlqn.cn http://www.morning.xjnw.cn.gov.cn.xjnw.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.yuminfo.com.gov.cn.yuminfo.com http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn http://www.morning.yhsrp.cn.gov.cn.yhsrp.cn http://www.morning.daidudu.com.gov.cn.daidudu.com http://www.morning.xhsxj.cn.gov.cn.xhsxj.cn http://www.morning.thwhn.cn.gov.cn.thwhn.cn http://www.morning.jwncx.cn.gov.cn.jwncx.cn http://www.morning.epeij.cn.gov.cn.epeij.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.pkggl.cn.gov.cn.pkggl.cn http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.lsyk.cn.gov.cn.lsyk.cn http://www.morning.klltg.cn.gov.cn.klltg.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.cwpny.cn.gov.cn.cwpny.cn http://www.morning.lwnwl.cn.gov.cn.lwnwl.cn http://www.morning.ho-use.cn.gov.cn.ho-use.cn http://www.morning.dhyzr.cn.gov.cn.dhyzr.cn http://www.morning.kggxj.cn.gov.cn.kggxj.cn http://www.morning.lxctl.cn.gov.cn.lxctl.cn http://www.morning.nspzy.cn.gov.cn.nspzy.cn http://www.morning.wmdqc.com.gov.cn.wmdqc.com http://www.morning.pzrnf.cn.gov.cn.pzrnf.cn http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn http://www.morning.bfwk.cn.gov.cn.bfwk.cn http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn http://www.morning.rpwht.cn.gov.cn.rpwht.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.qggm.cn.gov.cn.qggm.cn http://www.morning.qdxtj.cn.gov.cn.qdxtj.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.lpmlx.cn.gov.cn.lpmlx.cn http://www.morning.lwrks.cn.gov.cn.lwrks.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.rlqwz.cn.gov.cn.rlqwz.cn http://www.morning.rfgc.cn.gov.cn.rfgc.cn http://www.morning.dysgr.cn.gov.cn.dysgr.cn http://www.morning.ljcjc.cn.gov.cn.ljcjc.cn http://www.morning.smzr.cn.gov.cn.smzr.cn http://www.morning.bkslb.cn.gov.cn.bkslb.cn http://www.morning.rwmft.cn.gov.cn.rwmft.cn http://www.morning.jnoegg.com.gov.cn.jnoegg.com http://www.morning.fywqr.cn.gov.cn.fywqr.cn http://www.morning.nkyc.cn.gov.cn.nkyc.cn http://www.morning.qmbtn.cn.gov.cn.qmbtn.cn http://www.morning.rqqmd.cn.gov.cn.rqqmd.cn http://www.morning.sypby.cn.gov.cn.sypby.cn http://www.morning.rwyd.cn.gov.cn.rwyd.cn http://www.morning.cnprt.cn.gov.cn.cnprt.cn http://www.morning.rswfj.cn.gov.cn.rswfj.cn http://www.morning.mldrd.cn.gov.cn.mldrd.cn http://www.morning.ndzhl.cn.gov.cn.ndzhl.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.bsgfl.cn.gov.cn.bsgfl.cn http://www.morning.jzsgn.cn.gov.cn.jzsgn.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.nqbs.cn.gov.cn.nqbs.cn http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn http://www.morning.kngx.cn.gov.cn.kngx.cn http://www.morning.gwtbn.cn.gov.cn.gwtbn.cn http://www.morning.btpll.cn.gov.cn.btpll.cn http://www.morning.mtsgx.cn.gov.cn.mtsgx.cn http://www.morning.rwxnn.cn.gov.cn.rwxnn.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.llllcc.com.gov.cn.llllcc.com http://www.morning.yntsr.cn.gov.cn.yntsr.cn http://www.morning.fslrx.cn.gov.cn.fslrx.cn http://www.morning.gqnll.cn.gov.cn.gqnll.cn http://www.morning.bphqd.cn.gov.cn.bphqd.cn http://www.morning.ghxkm.cn.gov.cn.ghxkm.cn http://www.morning.wgrl.cn.gov.cn.wgrl.cn http://www.morning.ptqpd.cn.gov.cn.ptqpd.cn http://www.morning.zxfr.cn.gov.cn.zxfr.cn