当我重新填充我的时候ListView,我会用我的方法调用一个特定的方法Adapter.
问题:
当我打电话updateReceiptsList给我时Adapter,数据会刷新,但我ListView没有反映这一变化.
问题:
ListView我打电话时为什么不显示新数据notifyDataSetChanged?
适配器:
public class ReceiptListAdapter extends BaseAdapter {
public List<Receipt> receiptlist;
private Context context;
private LayoutInflater inflater;
private DateHelpers dateH;
public ReceiptListAdapter(Activity activity, Context mcontext, List<Receipt> rl) {
context = mcontext;
receiptlist = rl;
Collections.reverse(receiptlist);
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
dateH = new DateHelpers();
}
@Override
public int getCount() {
try {
int size = receiptlist.size();
return size;
} catch(NullPointerException ex) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Google广告DFP实施多种广告尺寸,如文档中所述
但奇怪的是,如果我使用单个广告尺寸,如下面的代码所示,它的工作原理如下:
_adView = new PublisherAdView(activity);
_adView.setAdSizes(AdSize.BANNER);
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用多个广告,与文档中描述的方式相同,如下所示,请求将失败:
_adView = new PublisherAdView(activity);
_adView.setAdSizes(AdSize.BANNER, new AdSize(120, 20), new AdSize(250, 250));
Run Code Online (Sandbox Code Playgroud)
因此,第一个代码段工作并提供广告,而第二个代码段在logcat中提供以下内容:
12-07 12:17:17.082 30786-30786/app.myappname.nl I/Ads? Ad opening.
12-07 12:17:17.109 30786-30812/app.myappname.nl W/Ads? The ad response must specify one of the supported ad sizes.
12-07 12:17:17.167 30786-30786/app.myappname.nl I/Ads? Scheduling ad refresh 60000 milliseconds from now.
12-07 12:17:17.167 30786-30786/app.myappname.nl W/Ads? Failed to load ad: 0
Run Code Online (Sandbox Code Playgroud)
我也尝试过只使用标准广告尺寸,但这并没有任何区别.有谁知道为什么会发生这种情况以及如何解决它?
我目前正在使用GSON使用输入流/阅读器解析一个非常大的JSON文件.在我的Android设备上解析大约需要35秒,我从一些基准测试中了解到Jackson性能更好.但是我无法找到如何使用jackson解析我的JSON文件.谁能帮我?
我的JSON看起来像这样:
[
{
"venue": { … }
},
{
"venue": {
"venue_seasons": [ … ],
"address": "the address",
"city": "the city",
"name": "the name",
"created_at": "2011-05-31T07:55:33Z",
"latitude": 00.000000,
"country": "the country",
"internal_link_en": null,
"internal_link_nl": null,
"updated_at": "2011-09-15T14:46:09Z",
"zipcode": "the zipcode",
"foursquare_link": "foursquare url",
"url": null,
"id": 3,
"tip": "some tip",
"uid": "4ab5e205f964a520317620e3",
"phone": "phonenr",
"recommended": null,
"website": "someurl",
"venue_photos": [ … ], //array containing objects with urls of images
"description": null,
"longitude": 00.000000,
"thumbnail_location": null,
"subcategories": [ … ], …Run Code Online (Sandbox Code Playgroud) 我使用FragmentPagerAdapter从片段切换.我需要在制作片段开关时调用一些函数,并且在OnPause和OnResume上遇到一些麻烦,所以这个问题的建议我实现了一个接口OnPageSelectListener:
public interface OnPageSelectListener {
void onPageSelected();
void onPageNotVisible();
}
Run Code Online (Sandbox Code Playgroud)
只要此页面到达前台,它就会调用OnPageSelected函数.工作得很好,除了我想在我的适配器上调用一个函数.我认为这样可行,除了我的适配器一直返回NULL(即使它被初始化并且数据在我的列表视图中被加载为首选).
public class AfterCheckFragment extends Fragment implements OnPageSelectListener{
private ListView listView;
private List<Check> checkList;
private CheckListAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_check, container, false);
System.out.println("VIEW create called");
//(.. some other stuff, not relevant for question..)
//initializing the adapter
listView = (ListView) view.findViewById(R.id.listView);
adapter = new CheckListAdapter(checkList,getActivity(),trainPosition);
listView.setAdapter(adapter);
adapter.handleButtonVisibility();
return view;
}
@Override …Run Code Online (Sandbox Code Playgroud) android oncreate android-fragments android-viewpager fragmentpageradapter
我有一个问题,为我想要使用json解析的json创建映射.它非常具体,它关于一个带有json数组的json文件,其中有对象.
我的jsonfile像这样开始:
[
{
"venue": {
"venue_seasons": [
{
"created_at": "2011-12-25T23:00:28Z",
"updated_at": "2011-12-28T15:13:53Z",
"start_timestamp": 1293840000,
"id": 337,
"end": "2011-12-24T00:00:00Z",
"enabled": true,
"start": "2011-01-01T00:00:00Z",
"season_openings": [ … ],
"end_timestamp": 1324684800
},
{ … }
],
"address": "someadress",
"city": "cityname",
"name": "name",
"created_at": "2011-03-31T07:55:33Z",
etcetera
}
"venue":{another venue
Run Code Online (Sandbox Code Playgroud)
所以首先是一个数组,而不是一个包含大量对象的对象(场所)(我删除了大部分对象,因为这对我的问题并不重要),以及一些数组(如season_openings).
我的解析代码就是这样的,我使用gson.输入流工作正常.
Reader reader = new InputStreamReader(inputStream);
JsonResponse venueResponse = gson.fromJson(reader, JsonResponse.class);
List<Venues> results = venueResponse.venue;
Run Code Online (Sandbox Code Playgroud)
与JsonResponse类:
public class JsonResponse {
public List<Venues> venue;
}
Run Code Online (Sandbox Code Playgroud)
和Venues.class:
public class Venues {
public List<VenueSeasons> venue_seasons;
@SerializedName("adress") …Run Code Online (Sandbox Code Playgroud) 我想在我的Android应用程序中集成flurry分析,它看起来非常简单.但我不熟悉乱舞及其运作方式.
我应该添加代码:
public void onStart()
{
super.onStart();
FlurryAgent.onStartSession(sample, “APIXXXXXXXXXXXX”);
}
Run Code Online (Sandbox Code Playgroud)
在每个活动?
我的应用程序使用了很多活动,我并不真正关心跟踪使用哪些活动,只关注安装次数,会话次数和会话长度.但是,如果仅在启动活动中添加了flurry代码,那么会话长度是否可用?
我知道我想要的大部分信息已经在Play商店中提供,但我想尝试这一点来概述不同平台上的应用程序.
我有一个两难的使用方法
if (convertview==null){
(my code)
}
Run Code Online (Sandbox Code Playgroud)
或不.没有这段代码,我的listview不是很快,它有时会锁定几毫秒,你可以很容易地注意到它在使用中.它无法正常工作.
但是当这段代码时,我的listitems会在一段时间后开始重新计算(10左右)并且我的列表中有一些返回的listitems(使用了我使用的标题).我使用本教程来获取带有部分链接的 listview .列表的长度很好.
当然,我的列表完全没用,有一个重复项目的视图(很好地按路划分),但我也不希望它很慢.有谁知道该怎么办?以下是我的适配器:
公共类DelftAdapter扩展BaseAdapter {
private Activity activity;
private List<ListItem> listItems;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
private final int[] bgColors = new int[] { R.color.list_odd, R.color.list_even };
public DelftAdapter(Activity a, ArrayList<ListItem> li) {
activity = a;
listItems = li;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return listItems.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Android应用程序,它应该将Json从文件或url解析为jsonarray和jsonobjects.问题是我的json是3.3 MB,当我使用一个简单的代码时,就像这样:(现在无法访问我的真实代码,因为我在工作中,从教程中复制了一些代码;因此可能会有一些错误)
(假设我已经拥有输入流内容)
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
String twitterfeed = builder.toString();
}
JSONArray jsonArray = new JSONArray(twittefeed);
Log.i(ParseJSON.class.getName(),
"Number of entries " + jsonArray.length());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
Log.i(ParseJSON.class.getName(), jsonObject.getString("text"));
Run Code Online (Sandbox Code Playgroud)
当我在我的Android设备上运行此代码时,我将字符串解析为jsonArray时出现OutOfMemory错误.我记录了一些东西,我发现我的总字符串是17 MB(一个3.3 MB的json文件?!)当我使用一个小的json文件,如twitterfeed左右,代码工作正常.当我在我的内存中得到这个17 MB的字符串时,我无法解析json,因为那时我的内存耗尽了.
经过大量的研究,我发现杰克逊可能是我的解决方案,因为我知道可以解析输入流.这应该有帮助,因为我不需要记忆中的17 mb字符串; 这不是我认为最有效的方式......但是我无法明白这一点真的会起作用,并且没有让它自己运行.有谁知道这真的会起作用,我在哪里可以找到一个教程?
我找到了"createJsonParser - public JsonParser createJsonParser(InputStream in)"并认为这是我的方式......但我不知道如何在我的代码中实现这一点,并且找不到示例.有谁知道这是如何工作的?
是否有可能从堆栈中重新打开特定活动?所以说我打开活动a,然后是b,然后是c.我在开始新活动时没有完成a和b.如果按下我的后按钮而没有覆盖它,我当然会去B.
但我想给一个按钮或者后面的按钮打开A,或者B独立于它在堆栈中的位置.这可以通过完成活动来实现(如果我完成b,并按下C的后退按钮,我会去A).但是我的一些活动我不想完成.
我研究过但无法找到如何实现这一目标.这可能吗?
当然,如果活动处于活动状态,则需要进行检查,如果是,则重新打开或打开它.
我正在为我的学士论文设计一个程序,根据z位置(电缆中的位置)显示钢丝绳的内部几何形状.
为了测试我"穿过"一段电缆,用这段代码(sl是一个链表,已经初始化,工作正常):
Cable c = new Cable(sl);
ImageFrame ts = new ImageFrame(c);
try {
while (location <2 ) {
location = location + 0.01;
Thread.sleep(100);
c.update(location);
ts.repaint();
}
System.exit(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
电缆功能update应该重新计算电缆的几何形状.我的类电缆有一个绞线列表,这个update函数的作用就是调用所有这些绞线的更新函数:
public void update(double z) {
for(int i=0;i<strandList.size() ;i++) {
strandList.get(i).updateStrand(z);
}
}
Run Code Online (Sandbox Code Playgroud)
该对象Strand如下所示:
public abstract class Strand {
Punt middenCable;
final Punt nulpoint_midden;
Punt midden;
Double angle;
Double d_to_core;
Image img;
int img_size;
BufferedImage bf; …Run Code Online (Sandbox Code Playgroud) android ×9
json ×3
gson ×2
jackson ×2
listview ×2
admob ×1
baseadapter ×1
convertview ×1
final ×1
flurry ×1
google-dfp ×1
java ×1
oncreate ×1
parsing ×1
performance ×1
request ×1
stack ×1