android-arrayadapter 相关问题

由任意对象数组支持的具体BaseAdapter。

什么是“ android.r.layout.simple_list_item_1”?

我已经开始学习Android开发,并遵循一本书中的招待示例: // Create the array list of to do items final ArrayList<String> todoItems = new ArrayList<String>(); // Create the array adapter to bind the array to the listView final ArrayAdapter<String> aa; aa = new ArrayAdapter<String>( this, android.R.layout.simple_list_item_1, todoItems ); myListView.setAdapter(aa); 我无法完全理解此代码,尤其是此行: android.R.layout.simple_list_item_1 Zakaria,这是对Android OS一部分的内置XML布局文档的参考,而不是您自己的XML布局之一。 there是您可以使用的另一个布局列表: http://developer.android.com/reference/android/r.layout.html (更新链接谢谢@estel:Https://github.com/android/platform_frameworks_base/tree/master/master/core/core/res/res/res/layout) 您实际上可以查看布局的代码。 这是Android OS的一部分。这是已定义的XML文件的实际版本。 SIMPLE_LIST_ITEM_1: <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="?android:attr/listItemFirstLineStyle" android:paddingTop="2dip" android:paddingBottom="3dip" android:layout_width="fill_parent" android:layout_height="wrap_content" /> SIMPLE_LIST_ITEM_2: <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android" android:paddingTop="2dip" android:paddingBottom="2dip" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" style="?android:attr/listItemFirstLineStyle"/> <TextView android:id="@android:id/text2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@android:id/text1" style="?android:attr/listItemSecondLineStyle" /> </TwoLineListItem> 以上回答:Kcoppock和Joril go在这里:https://github.com/android/platform_frameworks_base/tree/master/master/core/core/res/res/res/layout 右键单击您想要的布局文件,然后选择“保存为”,保存在某处,然后在Android Project(Eclipse)中的“布局”文件夹中复制它... 您可以看到布局的外观:) 走了... klap“ android.r.layout.simple_list_item_1是对android OS一部分的内置XML布局文档” 所有布局都位于:SDK \ Platforms Ndroid-XX \ Data中 es \layout 查看布局的XML: eclipse:简单地键入Android.r.layout.simple_list_item_1在代码中的某个地方,握住Ctrl,悬停在Simple_List_Item_1上,然后从下拉列表中选择“在Layout/Simple_list_item_item_1.xml中选择“打开声明”。它会将您引向XML的内容。 AndroidStudio:项目窗口 - >外部库 - > Android X Platform-> Res->布局,在这里您将看到可用布局的列表。 android.R.layout.simple_list_item_1,这是您的Res/Res/Layout文件夹中的行布局文件,其中包含listview中行的相应设计。现在,我们只使用mylistview.setadapter(aa);将数组列表项绑定到行布局中 无需转到外部链接,您需要的所有内容都位于计算机上: android ndroid-sdk \ platforms ndroid-x \ data es \layout. 这里都位于所有Android布局的代码代码。 per arvand: eclipse:只需键入android.r.layout.simple_list_item_1在代码中某个地方,握住ctrl,悬停在SIMPLE_LIST_ITEM_1上,然后从出现的下拉中选择“ layout/simple_list_list_item_item_item_1.xml”中的“选择”下拉。它会将您引向XML的内容。 从那里开始,如果然后将悬停在编辑器中的simple_list_item_1.xml选项卡中,您会看到该文件位于C:\ data Pplications \ android ndroid-ndroid-sdk \ android ndroid-sdk \ pl而且来数据 es \ layout \simple_list_item_1.xml(或安装的等效位置)。 我知道这个问题已经回答。 在搜索这个布局时,我想看看这种布局和其他外观,因此我决定提供您质疑的布局和其他人的外观。 基于@kevin Coppock的答案,我选择了一些列表项目布局。 所有这些布局都在Android的标准集中: 1。 simple_list_item_1 2。 simple_list_item_2 3。 activity_list_item 4。 simple_expandable_list_item_1 5。 simple_expandable_list_item_2 6。 simple_list_item_single_choice 7。 simple_list_item_multiple_choice 8。 simple_list_item_checked

回答 8 投票 0

如何更新UI(ListView)收到数据库数据或按下按钮

I有一个列表视图,该列表代表订单列表,而ListAdapter将收到的数据从DB设置为listView,我想动态地做: 如果未选择或开始 油漆

回答 3 投票 0

Android 微调器显示对象引用而不是字符串

好的,我的旋转器有问题。它填充了从网络服务中提取的数据。我遇到的问题是,当未单击微调器时,而不是显示...

回答 5 投票 0

为什么列表视图刷新后线条是白色的?

我有一个代码,它加载新闻列表: public View onCreateView(LayoutInflater inflater, ViewGroup 容器, 捆绑已保存实例状态) { 查看view=inflater.infla...

回答 2 投票 0

ArrayAdapter 的默认布局

我目前正在使用阵列适配器。我在网上遇到的所有示例都使用单独的阵列适配器布局。我想知道它是否有默认布局。我的代码类似于...

回答 2 投票 0

为什么此示例中的自定义 ArrayAdapter 构造函数与超类构造函数不完全匹配?

我正在学习有关在 Android 中为 ListView 创建自定义 ArrayAdapter 的教程。以下是教程中的自定义适配器类: 公共类 NumbersViewAdapter 扩展 ArrayAdapter<

回答 1 投票 0

从数组适配器中删除数据时更新列表视图

我正在创建一个 listView 并在我的主要活动中为其设置一个自定义 arrayAdapter 。在适配器的 getView 方法中使用 onClickListener 来尝试删除单击的项目。它正在...

回答 2 投票 0

arrayAdapter 中的资源类型问题

ArrayAdapter arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, R.array.lsViewArray ); lsViewArray.XML: ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, R.array.lsViewArray ); lsViewArray.XML: <resources> <string-array name="lsViewArray"> <item>Magenta</item> <item>Green</item> <item>Blue</item> <item>Red</item> <item>Black</item> <item>Orange</item> <item>Purple</item> <item>Pink</item> <item>White</item> <item>Violet</item> <item>Saffron</item> <item>Yellow</item> <item>Brown</item> </string-array> </resources> 它给我带来了错误R.array.lsViewArray 错误:- 类型 id 的预期资源 除了在MainActivity中制作数组还能做什么 我想通过 lsViewArray.xml 访问它 或者我应该知道的其他方法 在当前代码中,您使用 R.array.lsViewArray 作为 textViewResourceId。 textViewResourceId 是要填充的布局资源中的 TextView 的 id。在您的情况下,要填充的布局资源是 android.R.layout.simple_list_item1。它不包含任何 ID 为 R.array.lsViewArray 的 Textview,因此您会收到错误。 要解决此问题,您可以使用接受 T[] 对象的构造函数。 首先,从您的资源中获取数组。为此,请输入: String[] lsViewArrayData = getResources().getStringArray(R.array.lsViewArray); 然后创建适配器并传递对象 lsViewArrayData: ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, lsViewArrayData);

回答 1 投票 0

即使在数组列表和adapter.notifyDataSetChanged()中添加数据后,回收器视图也不会显示

有一个RecyclerView suggestList,单击它的任何itemView,我们会得到adapterposition(),它通过一个函数从用于suggestList适配器的ArrayList获取值。现在,...

回答 1 投票 0

未解决的参考 getResources() Kotlin

所以我尝试访问代码中的 getResources() ,但由于某种原因它不断获得未解析的引用。我正在另一个类中为我的数组适配器执行此操作。是不是因为我没有...

回答 4 投票 0

使用数组适配器过滤ListView

我正在尝试使用 arrayadapter 过滤列表视图。 arraydapter 参数是 String[][]。问题是任何事情都会发生。我必须重写 Filter 接口吗?在这种情况下,请问可以吗...

回答 3 投票 0

设置 AppCompatAutoCompleteTextView 下拉宽度和边距

我有以下 AppCompatAutoCompleteTextView - 我有以下 AppCompatAutoCompleteTextView - <androidx.appcompat.widget.AppCompatAutoCompleteTextView android:id="@+id/phoneNumberPrefixTextView" style="@style/PrimaryEditText" android:layout_width="match_parent" android:layout_height="@dimen/credit_card_form_height" android:gravity="center" android:dropDownWidth="match_parent" android:inputType="number" android:maxLength="3" /> 使用以下列表项 XML - <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingHorizontal="@dimen/padding_16"> <androidx.appcompat.widget.AppCompatTextView android:id="@+id/country_edit_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginHorizontal="@dimen/padding_16" android:layout_marginVertical="@dimen/padding_16" android:fontFamily="@font/montserrat_regular" android:textColor="@color/light_black" android:textSize="@dimen/text_size_normal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" tools:text="Israel" /> <androidx.appcompat.widget.AppCompatTextView android:id="@+id/country_code_edit_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginHorizontal="@dimen/padding_4" android:fontFamily="@font/montserrat_regular" android:textColor="@color/fog_medium" android:textSize="@dimen/text_size_normal" app:layout_constraintBottom_toBottomOf="@+id/country_edit_text" app:layout_constraintStart_toEndOf="@+id/country_edit_text" app:layout_constraintTop_toTopOf="@+id/country_edit_text" tools:text="+972" /> </androidx.constraintlayout.widget.ConstraintLayout> 以及以下 ArrayAdapter - class CountriesWithCodeAdapter( context: Context, resource: Int, private val items: MutableList<Countries.Country> ) : ArrayAdapter<Countries.Country>(context, resource, items) { private val originalList: List<Countries.Country> = items.toList() private var filteredItems: List<Countries.Country> = items.toList() override fun getItem(position: Int): Countries.Country { return items[position] } override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val binding: CreditCardCountryWithCodeItemBinding = if (convertView != null) { CreditCardCountryWithCodeItemBinding.bind(convertView) } else { CreditCardCountryWithCodeItemBinding.inflate( LayoutInflater.from(context), parent, false ) } binding.countryEditText.text = items[position].name binding.countryCodeEditText.text = items[position].callingCode return binding.root } override fun getFilter(): Filter = object : Filter() { override fun performFiltering(constraint: CharSequence?): FilterResults { val charString = constraint.toString().lowercase(Locale.getDefault()).trim() filteredItems = if (charString.isEmpty()) { originalList.toList() } else { originalList.filter { country -> country.callingCode.contains(charString, ignoreCase = true) } } val filterResults = FilterResults() filterResults.values = filteredItems return filterResults } override fun publishResults(constraint: CharSequence?, results: FilterResults?) { @Suppress("UNCHECKED_CAST") filteredItems = results?.values as? List<Countries.Country> ?: emptyList() if (filteredItems.isEmpty()) { clear() notifyDataSetChanged() } else { clear() addAll(filteredItems) notifyDataSetChanged() } } } } 我正在尝试实现一种在下拉项中引入填充的行为。我在设置 android:dropDownWidth="match_parent" 的同时添加了列表项填充到根父级,但它似乎实际上没有做任何事情。我错过了什么? 假设您正在尝试在自动完成文本视图上实现水平边距,您可以尝试为自动完成文本视图创建单独的布局,并将其包含在父布局中,如下所示,这将在自动完成文本视图上设置 16 的水平填充/边距: - 父级布局 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginHorizontal="16dp" tools:context=".messageCenter.MessageCenterFragment"> <include android:id="@+id/ilAutoCompleteTextView" layout="@layout/autocomplete_textview"/> </androidx.constraintlayout.widget.ConstraintLayout> 子布局 <?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" android:paddingBottom="16dp" android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp"> <AutoCompleteTextView android:id="@+id/autoCompleteTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#000" android:hint="Enter Your Name Here" android:padding="15dp" android:textColorHint="#fff" android:textStyle="bold|italic" /> </RelativeLayout> 现在是你的代码:- val fruits = arrayOf("Apple", "Banana", "Cherry", "Date", "Grape", "Kiwi", "Mango", "Pear") val adapter = ArrayAdapter(requireContext(), R.layout.select_dialog_item, fruits) //Getting the instance of AutoCompleteTextView val actv = binding.ilAutoCompleteTextView.autoCompleteTextView actv.threshold = 1 //will start working from first character actv.setAdapter(adapter) //setting the adapter data into the AutoCompleteTextView actv.setTextColor(Color.RED)

回答 1 投票 0

我可以在没有 ListView 的情况下使用适配器吗?

我从后端收到大量数据,我需要以不同的方式在应用程序的两个部分中显示这些数据,例如绘制实时图表。所讨论的部分中的 1 个是矩形,即...

回答 1 投票 0

ArrayAdapter 中何时使用构造函数一和构造函数二?

ArrayAapter 类有一些构造函数: 什么时候使用构造函数一和二?因为我们在这些构造函数中根本没有像输入数组或列表这样的数据结构。如果可能的话,解释一下...

回答 1 投票 0

从购物车中删除商品后更新购物车总金额

这是一个电子商务应用程序,我面临与从购物车(添加/删除)商品相关的问题,当我添加两个商品,然后如果我删除其中一个,总金额为 时,就会发生问题。 ..

回答 1 投票 0

如何在 ArrayAdapter 上设置 onClickListener?

我正在上课,如下所示 // 所有必要的导入都在这里 公共课更多扩展活动{ String[] MoreItems = { "转账", "预算", "分支机构", "工具", "新闻", “

回答 4 投票 0

Android - Material Exposed Dropdown Menu options not populating

我正在尝试创建一个材料公开的下拉菜单,该菜单在重新访问片段时会重建。初次访问片段时,菜单已正确创建(它有助于创建计时器)。前...

回答 1 投票 0


当通过意图获取数据并在列表视图中显示时,应用程序被停止。

我正在开发一个应用程序,在这个应用程序中,我将数据从一个活动发送到另一个活动,并在ListView中显示相同的数据。我的代码中没有错误,我也检查了Logcat错误,但没有任何错误,而且......

回答 1 投票 0

ArrayAdapter的空对象引用

我正试图将一个ArrayList适配到Fragment中的AutoCompleteTextView。我已经在另一个程序中使用了这个功能,我在MainActivity中应用了适配器。我得到的错误是...

回答 1 投票 -1

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.