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
最满意答案
在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 ...
-
Elastisearch并不将Unix时间戳视为有效的时间戳(Elastisearch is not treating Unix timestamps as valid timestamps)[2022-04-01]
您需要为@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 ...
-
MySQL查询Unix时间戳(MySQL Querying Unix Timestamps)[2022-07-07]
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 -
比较Unix时间戳(Comparing Unix timestamps)[2022-08-25]
$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 ...
-
我需要MySQL的SQLite等效物来处理unix时间戳(I need the SQLite equivalent of MySQL for working with unix timestamps)[2024-03-05]
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
-
unix时间戳和php(unix timestamps and php)[2023-11-25]
您可以使用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.