我正在为Android编写应用程序,但我遇到了这个问题。 基本上,应用程序显示电影列表,然后点击电影打开包含电影细节的活动,包括预告片。 我正在使用www.themoviedb.org提供的API。 我编写了一个自定义适配器,以便将它们(语言,网站,标题)的预告片和信息显示在DetailActivity中显示的列表视图中。 这是我的问题: 例如,预告片的json响应如下:
TGridLinkForm1 = class(TForm)
[...]
public
{ Public declarations }
DataFileName : String;
end;
procedure TGridLinkForm1.FormCreate(Sender: TObject);
begin
DataFileName := 'D:\xe8\samples\Data\Biolife.Fds';
if not FDMemTable2.Active then
FDMemTable2.LoadFromFile(DataFileName);
if not FDMemTable1.Active then
FDMemTable1.LoadFromFile(DataFileName);
end;
procedure TGridLinkForm1.FDMemTable1AfterScroll(DataSet: TDataSet);
var
SpeciesNo : Double;
begin
SpeciesNo := FDMemTable1.FieldByName('Species No').AsFloat;
if not FDMemTable2.Locate('Species No', SpeciesNo, []) then
raise Exception.CreateFmt('SpeciesNo %n not found in %s', [SpeciesNo, FDMemTable2.Name]);
end;
问题是:当我覆盖 object FDMemTable2: TFDMemTable
FetchOptions.AssignedValues = [evMode]
FetchOptions.Mode = fmAll
ResourceOptions.AssignedValues = [rvPersistent, rvSilentMode]
ResourceOptions.Persistent = True
ResourceOptions.SilentMode = True
UpdateOptions.AssignedValues = [uvCheckRequired]
UpdateOptions.CheckRequired = False
Left = 24
Top = 392
end
object DataSource2: TDataSource
DataSet = FDMemTable2
Left = 88
Top = 392
end
object BindSourceDB2: TBindSourceDB
DataSource = DataSource2
ScopeMappings = <>
Left = 236
Top = 392
end
object BindingsList2: TBindingsList
Methods = <>
OutputConverters = <>
Left = 152
Top = 392
object LinkControlToField1: TLinkControlToField
Category = 'Quick Bindings'
DataSource = BindSourceDB2
FieldName = 'Graphic'
Control = ImageWithHandler
Track = False
end
end
的{{1}}方法时,我必须返回{"id":135397,"results":[{"id":"54749bea9251414f41001b58","iso_639_1":"en","key":"bvu-zlR5A8Q","name":"Teaser","site":"YouTube","size":1080,"type":"Teaser"},{"id":"5474d2339251416e58002ae1","iso_639_1":"en","key":"RFinNxS5KN4","name":"Official Trailer","site":"YouTube","size":1080,"type":"Trailer"},{"id":"56404e639251417052000369","iso_639_1":"en","key":"aJJrkyHas78","name":"Official Global Trailer","site":"YouTube","size":1080,"type":"Trailer"}]}
值,但我无法转换getItemId
json
(例如字符串BaseAdapter
)到long
。
它看起来像十六进制,但它太大了。
到目前为止我试过了:
id
54749bea9251414f41001b58
方法获取值
long
方法getString
方法,将16作为基数在上面的所有情况中,结果总是相同的,这个例外:
jsonObject
有没有办法从这个邪恶的字符串中提取有效的id?或者“强制”Long.parse(String x)
从Long.parse(String x, int radix)
方法返回java.lang.NumberFormatException: Invalid long: "54749bea9251414f41001b58"
而不是BaseAdapter
?
提前致谢。我省略了所有java类的代码,因为我认为没有必要,我可以在需要时添加它。
答案 0 :(得分:1)
您可以从getItemId()方法返回位置,如
long getItemId(int position) {
return position;
}
或者,如果你已经创建了一个POJO,那么你可以这样做
long getItemId(int position) {
return yourItem.hashCode();
}