首页 \ 问答 \ ListFragment或Fragment中的自定义ListView?(Custom ListView in ListFragment or Fragment?)

ListFragment或Fragment中的自定义ListView?(Custom ListView in ListFragment or Fragment?)

我正在开发一个简单的应用程序,因此主要活动有两个用户可以滑动去的片段。 其中一个,我想要自定义列表。 例如,像这样的https://github.com/JakeWharton/SwipeToDismissNOA ,可以通过滑动删除列表中的每个项目。 我能够获得一个常规列表在ListFragment中工作,但无法使这个自定义列表工作。 据我所知,ListFragment需要有一个简单的.xml,但是我想要使用的那个,还有更多东西。 像这样的东西:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:padding="16dp">

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

    <TextView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:listSeparatorTextViewStyle"
        android:text="ListView" />

    <ListView
        android:id="@android:id/list"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />
</LinearLayout>

因此,当我尝试使用此.xml来获取getListView()时,它会返回null或当我尝试执行类似这样的操作时:View view = inflater.inflate(R.layout.fragment_section_dummy,null); ListView ls =(ListView)view.findViewById(android.R.id.list);

它抛出此错误:10-15 20:25:28.895:E / AndroidRuntime(8081):java.lang.UnsupportedOperationException:AdapterView不支持addView(View,LayoutParams)。

谢谢。


I am working on a simple app, so that the main activity has two fragments that user can swipe to go to. On one of them, I want to have custom list. For example, something like this https://github.com/JakeWharton/SwipeToDismissNOA, where each item in the list can be deleted by swiping. I was able to get a regular list to work inside the ListFragment, but can't get this custom list to work. As I understand, ListFragment needs to have a simple .xml with one , but the one that I want to use, has a bit more stuff in it. Something like this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false"
android:padding="16dp">

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

    <TextView android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:listSeparatorTextViewStyle"
        android:text="ListView" />

    <ListView
        android:id="@android:id/list"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />
</LinearLayout>

So when I am trying to getListView() using this .xml, it either returns null or when I am trying to do something like this: View view = inflater.inflate(R.layout.fragment_section_dummy, null); ListView ls = (ListView) view.findViewById(android.R.id.list);

It throws this error: 10-15 20:25:28.895: E/AndroidRuntime(8081): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView.

Thanks.


原文:https://stackoverflow.com/questions/26395762
更新时间:2023-04-22 12:04

最满意答案

在Linux中可以使用:

date +%s

哪里

  • +%s ,自1970-01-01 00:00:00 UTC以来的秒数。 (GNU Coreutils 8.24日期手册)

示例输出现在1454000043。


In Linux or MacOS you can use:

date +%s

where

  • +%s, seconds since 1970-01-01 00:00:00 UTC. (GNU Coreutils 8.24 Date manual)

Example output now 1454000043.

相关问答

更多
  • 可以调用plt.plot(dates,values) , dates是datetime.datetime对象的列表。 情节将包括像'%Y-%m-%d'这样的格式的xticks,并且在您放大时会自动更改为显示小时,分钟和秒的格式。 但是,这听起来像你想要更多的控制比这个。 也许它不会显示您希望的规模的小时,分钟,秒。 在这种情况下,您可以设置自己的日期格式化程序: ax=plt.gca() xfmt = md.DateFormatter('%Y-%m-%d %H:%M:%S') ax.xaxis.set_ma ...
  • 在Linux中可以使用: date +%s 哪里 +%s ,自1970-01-01 00:00:00 UTC以来的秒数。 (GNU Coreutils 8.24日期手册) 示例输出现在1454000043。 In Linux or MacOS you can use: date +%s where +%s, seconds since 1970-01-01 00:00:00 UTC. (GNU Coreutils 8.24 Date manual) Example output now 14540000 ...
  • 您需要为@timestamp字段定义显式映射作为date类型,以便索引unix timestamp值,否则Elasticsearch会将它们视为long类型。 因此,在将unix timestamp值编入@timestamp字段之前,请按如下所示定义映射: PUT myindex { "mappings": { "regionserver.Regions": { "properties": { "@timestamp": { "type": " ...
  • 但是,您选择存储时间戳,避免区域解释问题和时间偏移问题很重要。 Unix时间戳被解释为相同的区域,并且是从相同的时间点计算而不管时区 - 这些都是好的事情。 谨防将时间戳存储为不确定的字符串,如01/02/2008,因为可以解释为2008年1月2日或2008年2月1日,具体取决于语言环境。 当存储小时/分/秒时,重要的是要知道“指定哪个”小时/分钟。 您可以通过包含时区信息(Unix时间戳不需要,因为它被假定为UTC)来实现。 但是请注意,Unix时间戳不能及时地代表一些时刻:当UTC中有一个闰秒时,Uni ...
  • SELECT * FROM your_table WHERE DAYOFWEEK(FROM_UNIXTIME(your_unix_timestamp_column)) = 2 SELECT * FROM your_table WHERE DAYOFWEEK(FROM_UNIXTIME(your_unix_timestamp_column)) = 2
  • $three_min_from_now = mktime(0, 3, 0, 0, 0, 0); if (time() >= $filemodtime + $three_min_from_now) { 你在这里做的是检查time()是否大于文件修改的unix时间戳,加上从现在起三分钟的unix时间戳。 这是非常非常不可能的 - 你只需要在$ filemodtime中添加180就好了: if (time() >= $filemodtime + (60 * 3)) { $three_min_from_now ...
  • 如果你想设置你的时区并使它们在PHP和Python中保持一致,那么你的PHP代码是完全正确的,对于python你需要应用以下内容: os.environ['TZ'] = 'America/New_York' time.tzset() 在调用strftime() 这应该确保您将时间存储在您尝试检索它的同一区域中。 注意: tzset()是一个仅限Unix的函数。 If you want to set your timezones and keep them aligned in PHP and in Pyt ...
  • SQLite日期和时间函数记录在http://sqlite.org/lang_datefunc.html 。 相当于你的WHERE子句是 WHERE date(COLUMN_DATE,'unixepoch') = date('now') SQLite date and time functions are documented at http://sqlite.org/lang_datefunc.html. The equivalent of your WHERE clause would be WHER ...
  • 好吧,30天是60 * 60 * 24 * 30 = 2592000秒,所以只需将差值除以该数字: (endTime - startTime) / 2592000 Well, 30 days are 60*60*24*30=2592000 seconds, so just divide the difference with that number: (endTime - startTime) / 2592000
  • 您可以使用mktime()生成当天开始的时间戳,然后查找时间戳大于该值的数据库条目。 you can use mktime() to generate the timestamp for the start of the day and then find the database entries with a timestamp greater than that.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)