在循环中的imageview中显示图像(showing images in an imageview in a loop)
我在sd卡上的应用程序中有一些图像,我想在一段时间内逐个向用户显示这些图像,让我们说一个图像然后一个一分钟后的另一个图像,然后像这样一分钟后另一个图像。我正在使用aysnctask这是我在位图中转换图像并显示它。我想在连续循环中显示这些图像,直到用户从应用程序存在应用程序应该逐个显示图像我正在使用以下代码: -
for(i=1;i<z-1;i++) { xc=cont_id.get(1).toString(); what=Environment.getExternalStorageDirectory() + "/Playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new Showtime().execute(what,play_duration); Log.i("lenght",String.valueOf(i));}
但当我尝试在无限循环中执行它时,我的应用程序崩溃: -
for(i=1;i<z-1;i++) { xc=cont_id.get(1).toString(); what=Environment.getExternalStorageDirectory() + "/Playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new Showtime().execute(what,play_duration); Log.i("lenght",String.valueOf(i)); if(i=Z-1){ i=1; }}
我的应用程序崩溃请有人建议我如何实现它..现在我的应用程序没有崩溃,但它没有显示我的logcat在下面的任何图像
09-04 12:11:31.807: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:31.807: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 80-byte allocation 09-04 12:11:32.182: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.182: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 372ms, total 372ms 09-04 12:11:32.182: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:32.182: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 20-byte allocation 09-04 12:11:32.182: D/dalvikvm(4358): WAIT_FOR_CONCURRENT_GC blocked 8390ms 09-04 12:11:32.557: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.557: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 380ms, total 380ms 09-04 12:11:32.557: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:32.557: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 12-byte allocation 09-04 12:11:32.932: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.932: D/dalvikvm(4358): GC_CONCURRENT freed 0K, 2% free 48571K/49159K, paused 2ms+3ms, total 371ms 09-04 12:11:32.932: D/dalvikvm(4358): WAIT_FOR_CONCURRENT_GC blocked 369ms 09-04 12:11:33.292: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:33.292: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 362ms, total 362ms 09-04 12:11:33.292: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:33.292: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 110-byte allocation 09-04 12:11:33.659: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:33.659: D/dalvikvm(4358): GC_FOR_ALLOC freed <1K, 2% free 48571K/49159K, paused 362ms, total 362ms 09-04 12:11:33.659: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:33.659: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 24-byte allocation 09-04 12:11:34.026: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:34.026: D/dalvikvm(4358): GC_FOR_ALLOC freed <1K, 2% free 48571K/49159K, paused 368ms, total 368ms 09-04 12:11:34.026: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB
而且更像这样
I have some images in my app on sd card and i want to show these images to user one by one for some duration, lets say one image then other one after one minute then another one after one minute like this.I am using aysnctask for this in which i convert the image in a bitmap and show it.I want to show these images in a continous loop until user exists from the app the app should show images one by one i am using the following code for it:-
for(i=1;i<z-1;i++) { xc=cont_id.get(1).toString(); what=Environment.getExternalStorageDirectory() + "/Playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new Showtime().execute(what,play_duration); Log.i("lenght",String.valueOf(i));}
but when i try to execute it in an endless loop like this my app crashes:-
for(i=1;i<z-1;i++) { xc=cont_id.get(1).toString(); what=Environment.getExternalStorageDirectory() + "/Playerimages/" + xc + ".jpg"; play_duration=durat.get(1); //s1.execute(what,play_duration); new Showtime().execute(what,play_duration); Log.i("lenght",String.valueOf(i)); if(i=Z-1){ i=1; }}
my app crashed please someone suggest how can i achieve it.. now my app is not crashing but it is not showing any images my logcat is below
09-04 12:11:31.807: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:31.807: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 80-byte allocation 09-04 12:11:32.182: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.182: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 372ms, total 372ms 09-04 12:11:32.182: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:32.182: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 20-byte allocation 09-04 12:11:32.182: D/dalvikvm(4358): WAIT_FOR_CONCURRENT_GC blocked 8390ms 09-04 12:11:32.557: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.557: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 380ms, total 380ms 09-04 12:11:32.557: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:32.557: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 12-byte allocation 09-04 12:11:32.932: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:32.932: D/dalvikvm(4358): GC_CONCURRENT freed 0K, 2% free 48571K/49159K, paused 2ms+3ms, total 371ms 09-04 12:11:32.932: D/dalvikvm(4358): WAIT_FOR_CONCURRENT_GC blocked 369ms 09-04 12:11:33.292: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:33.292: D/dalvikvm(4358): GC_FOR_ALLOC freed 0K, 2% free 48571K/49159K, paused 362ms, total 362ms 09-04 12:11:33.292: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:33.292: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 110-byte allocation 09-04 12:11:33.659: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:33.659: D/dalvikvm(4358): GC_FOR_ALLOC freed <1K, 2% free 48571K/49159K, paused 362ms, total 362ms 09-04 12:11:33.659: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB 09-04 12:11:33.659: I/dalvikvm-heap(4358): Grow heap (frag case) to 48.000MB for 24-byte allocation 09-04 12:11:34.026: I/dalvikvm-heap(4358): Clamp target GC heap from 50.002MB to 48.000MB 09-04 12:11:34.026: D/dalvikvm(4358): GC_FOR_ALLOC freed <1K, 2% free 48571K/49159K, paused 368ms, total 368ms 09-04 12:11:34.026: I/dalvikvm-heap(4358): Clamp target GC heap from 48.002MB to 48.000MB
and much more like this
原文:https://stackoverflow.com/questions/18606659
最满意答案
你可以使用全熊猫的方法; 将您的元组转换为数据帧并将其与原始数据合并:
tuples_as_df = pd.DataFrame(tup, columns=['dummy','bin']) df = df.merge(tuples_as_df, how='left', left_on='Num', right_on='dummy') del df['dummy'] # The merge key, not needed anymore # Num bin #0 1 0 #1 2 1 #2 3 0 #3 4 1 #4 1 0 #5 2 1 #....
You can use an all-Pandas approach; convert your tuples into a dataframe and merge it with the original data:
tuples_as_df = pd.DataFrame(tup, columns=['dummy','bin']) df = df.merge(tuples_as_df, how='left', left_on='Num', right_on='dummy') del df['dummy'] # The merge key, not needed anymore # Num bin #0 1 0 #1 2 1 #2 3 0 #3 4 1 #4 1 0 #5 2 1 #....
相关问答
更多-
Pandas数据框 - 基于简单的计算创建新列(Pandas dataframe - create new column based on simple calcuation)[2023-01-02]
你可以使用numpy.where()方法: In [241]: x Out[241]: rating_1 time_1 rating_2 time_2 col_x col_y 0 11 1 21 1 1 1 1 12 2 21 1 1 1 2 13 1 21 5 1 1 3 ... -
你可以使用全熊猫的方法; 将您的元组转换为数据帧并将其与原始数据合并: tuples_as_df = pd.DataFrame(tup, columns=['dummy','bin']) df = df.merge(tuples_as_df, how='left', left_on='Num', right_on='dummy') del df['dummy'] # The merge key, not needed anymore # Num bin #0 1 0 #1 2 ...
-
有什么方法可以从熊猫中的浮动列创建一列元组?(Any way to create a column of tuples from a column of floats in pandas?)[2022-01-02]
我首先要从你的元组列表中创建一个Series : LS = pd.Series(ls) 然后调用map : data['ls'] = data['ind'].map(LS) 使用列表示例: ls = [(14, 6, 1.5), (14, 7, 1.5), (14, 8, 1.5), (14, 9, 1.5), (14, 10, 1.5), (14, 11, 1.5), (14, 12, 1.5)] 和这个: data = pd.DataFrame({'ind':[0,2,3]}) 执行查找会导致: ... -
您可以使用pd.MultiIndex.from_product ,它使用来自多个迭代的笛卡尔积的MultiIndex : import pandas as pd pd.DataFrame(columns=pd.MultiIndex.from_product([column1, column2], names=['Large index', 'Small index'])) #Large index A B C #Small index a b c ...
-
您可以将列名称的值压缩为列表: In [127]: list(zip(df.columns,df.T.values.tolist())) Out[127]: [('a', [1, 3]), ('b', [2, 4])] You can zip the column names with the values as lists: In [127]: list(zip(df.columns,df.T.values.tolist())) Out[127]: [('a', [1, 3]), ('b', [2, ...
-
如何将dicts元组列表转换为pandas数据帧(How to transform list of tuples of dicts to a pandas dataframe)[2022-07-17]
使用普通的旧字典合并,通过pythonic(Python 3.5+)方式合并起始和结束字典,然后使用from_records构建DataFrame 。 pd.DataFrame.from_records([{**d[0],**d[1]} for d in k]) chrom gEnd gStart pEnd pStart 0 chr1 2000 1000 2500 1500 1 chr2 8500 8000 9500 7500 Using plain ol ... -
df['combo'] = df.apply(lambda x: '-'.join(list(x[x == 1].index)).replace('test', ''), axis=1) 产生以下输出: In [8]: df Out[8]: test1 test2 test3 combo 0 0 1 1 2-3 1 0 1 0 2 2 1 1 1 1-2-3 3 1 ...
-
你可以爆炸df和plot In [3129]: s = df.y.map(ast.literal_eval) In [3130]: dff = pd.DataFrame({'x': df.x.repeat(s.str.len()).values, 'y': np.concatenate(s.values)}) In [3131]: dff Out[3131]: x y 0 1 5 1 1 27 2 1 4 3 2 ...
-
您可以使用to_dict方法从df2创建dict ,然后map结果map到df1 Type列: replace_dict = dict(df2.to_dict('split')['data']) In [50]: replace_dict Out[50]: {'A': 1, 'B': 2, 'C': 3, 'D': 4, 'E': 5, 'F': 6} df1['Value'] = df1['Type'].map(replace_dict) In [52]: df1 Out[52]: Type ...
-
一个非常基本的方法就是过滤布尔字典然后直接分配。 to_rep = [k for k in replace if replace[k]] df_old[to_rep] = df_new[to_rep] 如果您想保留旧的DataFrame,可以使用assign() df_old.assign(**{k: df_new[k] for k in replace if replace[k]}) 正如Nickil所提到的,当我们传递一个字典时, assign()显然不会保留参数顺序。 但是为了可预测,它会在Dat ...