这是片段的代码,我在其中为列表设置自定义适配器.
没有错误,但是ListView空的.我实现getCount()了在ArrayList中返回正确数量的项目.我没有("Inside", "GetView")在logcat中看到
分段
public class ServiceCarListFragment extends Fragment {
private String url;
private ArrayList<CarDetail> carDetailList = new ArrayList<CarDetail>();
private CarListAdapter adapter;
private ListView mList;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
url = getActivity().getIntent().getStringExtra("url");
new DownloadCarDetail().execute(url);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View v = inflater.inflate(R.layout.fragment_service_car_list, container, false);
mList = (ListView) v.findViewById(R.id.list);
mList.setAdapter(adapter);
for (CarDetail car : carDetailList) …Run Code Online (Sandbox Code Playgroud) 我有一个带有a 的自定义适配器,ListFragment但getView()根本没有调用适配器.
这是适配器的样子 -
public class ModuleListItemAdapter extends BaseAdapter {
List<ModuleItem> list;
Context context;
Module mod;
public ModuleListItemAdapter() {
super();
// TODO Auto-generated constructor stub
}
public ModuleListItemAdapter(Context context, List<ModuleItem> list, Module mod) {
super();
this.list = list;
this.context = context;
this.mod = mod;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.moduleitem, null);
GenerateModuleItemView gmiv …Run Code Online (Sandbox Code Playgroud) 我最近刚开始工作I/O在C.这是我的问题 -
我有一个文件,我从中读取了我的输入.然后我用来fgets()在缓冲区中获取字符串,我以某种方式使用它.现在,如果输入对于缓冲区而言太短,即第一次读取fgets()到达时会发生什么EOF.应该fgets()返回NULL(正如我在fgets()文档中看到的那样)?它似乎没有,我得到了正确的输入.除了我feof(input)不说我们已达到EOF.
这是我的代码片段.
char buf[BUFSIZ];
FILE *input,
*output;
input = fopen(argv[--argc], "r");
output = fopen(argv[--argc], "w");
/**
* If either of the input or output were unable to be opened
* we exit
*/
if (input == NULL) {
fprintf(stdout, "Failed to open file - %s.\n", argv[argc + 1]);
exit(EXIT_FAILURE);
}
if (output == NULL) {
fprintf(stdout, "Failed to …Run Code Online (Sandbox Code Playgroud) 我正在比较Swing SwingWorker和Android的AsyncTask类之间的差异.虽然Android有一个主线程/ UI线程,然后产生一个后台线程(使用AsyncTask),SwingWorker有三个涉及的线程 -
然后我也发现了声明(在文档中) -
通常,Current线程是Event Dispatch Thread.
现在,这是什么意思?
这是否意味着Swing也只有1个线程 - 主线程甚至事件都在同一个线程上接收或者 它对于不同的JVM实现是否不同?
我创建了一个Custom SeekBarPreference,它显示了一个从中选择的时间范围(例如0.2秒到2.2秒).我的问题是onProgressChanged()被调用两次 - 一次用progress = 0,第二次用progress = "actual value".我将值存储在a中,SharedPreference以便稍后在我的应用程序中使用它.
这是我的代码片段 -
@Override
protected View onCreateDialogView() {
LayoutInflater inflator = ((PreferenceActivity) mContext)
.getLayoutInflater();
View view = inflator.inflate(R.layout.seek_bar, null);
mCurrentValue = PreferenceManager.getDefaultSharedPreferences(mContext)
.getFloat(this.getKey(), mDefaultValue);
......
SeekBar mSeekBar = (SeekBar) view.findViewById(R.id.seekbar);
mSeekBar.setOnSeekBarChangeListener(this);
mSeekBar.setMax(20);
mSeekBar.setProgress((int) ((mCurrentValue - mMinValue)
/ (mMaxValue - mMinValue) * 20)); // 20 = progress bar max value.
return view;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) …Run Code Online (Sandbox Code Playgroud) 我正在尝试解析我在资源文件夹中的XML文件.这就是我要做的 -
public void loadXMLtoDB() {
Resources resource = mContext.getResources();
dbInstance = new DBProvider();
dbInstance.onCreate();
try{
XmlResourceParser parser = resource.getXml(R.xml.default_apps);
parser.nextTag();
readApps(parser);
} catch (Exception e) {
e.printStackTrace();
}
}....
private void readApps(XmlResourceParser parser) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, null, "appsList");
while(parser.next() != XmlPullParser.END_TAG){
if(parser.getEventType() != XmlPullParser.START_TAG)
continue;
String name = parser.getName();
if(name.equals("appIcon")){
readAppIcon(parser);
}
else
skip(parser);
}
} .....
Run Code Online (Sandbox Code Playgroud)
这是我的XML文件 -
<appsList xmlns:launcher="http://schemas.android.com/apk/res/com.example.kids" >
<appIcon>
<className>com.sec.android.app.camera.Camera</className>
<iconPosition>0</iconPosition>
<packageName>com.sec.android.app.camera</packageName>
<screen>0</screen>
</appIcon>
<appIcon>
<className>com.sec.android.gallery3d.app.Gallery</className>
<iconPosition>1</iconPosition>
<packageName>com.sec.android.gallery3d</packageName>
<screen>0</screen>
</appIcon>
</appsList>
Run Code Online (Sandbox Code Playgroud)
这是我得到的例外: …
我有一个数据类似的文件 -
Name, Age, Occupation
John, 14, Student
George, 14, Student
William, 23, Programmer
Run Code Online (Sandbox Code Playgroud)
现在,我想读取数据,使每个值(例如Name,Age等)作为字符串读取.
这是我的代码片段 -
....
if (!(ferror(input_fp) || ferror(output_fp))) {
while(fscanf(input_fp, "%30[^ ,\n\t]%30[^ ,\n\t]%30[^ ,\n\t]",
name, age_array, occupation) != EOF){
fprintf(stdout, "%-30s%-30s%-30s\n", name, age_array, occupation);
}
fclose(input_fp);
fclose(output_fp);
}
....
Run Code Online (Sandbox Code Playgroud)
然而,这会进入一个无限循环,给出一些随机输出.
这就是我理解我的方式input conversion specifiers.
%30[^ ,\n\t]- >读取最多30个字符的字符串,并且
不包括空格,逗号,换行符或制表符.
我正在阅读3个这样的字符串.
我哪里错了?
我的布局有一个CardView和一个FloatingActionButton相关的布局.下面有一个回复列表CardView(这是一个RecyclerView).有时CardViews'高度大于屏幕,所以我已经习惯layout_height="wrap_content"了CardView将整个LinearLayout内部包裹起来ScrollView.
但是,这会导致问题(因为它是一个内部的滚动视图ScrollView),同时滚动项目RecyclerView.正如在发布的一些问题和答案中所建议的那样,我已经使用了NestedScrollView和android:nestedScrollingEnabled="true"标签,但滚动RecyclerView仍然很糟糕.
这是我的Layout档案 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.forum.reply.ReplyActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/reply_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:titleTextColor="@android:color/white"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="@+id/topic_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/card_margin"
android:paddingLeft="@dimen/card_margin"
android:paddingRight="@dimen/card_margin"
android:paddingTop="@dimen/card_margin">
<LinearLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它使用第三方库 - 简单的Facebook - 来访问Facebook Graph API.此第三方库本身在内部使用 Facebook SDK作为库.

Compile, Provided, APK, Test compile, Debug compile and Release compile.
我们可以将源文件/ jar附加到eclipse中的库jar(如本例所示).这使得阅读使用的文档非常容易imports.Android Studio中有类似的东西吗?
我正在使用Retrofit来获取JSON回复.
以下是我实施的部分内容 -
@GET("/api/report/list")
Observable<Bills> listBill(@Query("employee_id") String employeeID);
Run Code Online (Sandbox Code Playgroud)
班级比尔是 -
public static class Bills {
@SerializedName("report")
public ArrayList<BillItem> billItems;
}
Run Code Online (Sandbox Code Playgroud)
该BillItem班是如下-
public static class BillItem {
@SerializedName("id")
Integer entryID;
@SerializedName("employee_id")
Integer employeeDBID;
@SerializedName("type")
String type;
@SerializedName("subtype")
String subtype;
@SerializedName("date")
String date;
@SerializedName("to")
String to;
@SerializedName("from")
String from;
@SerializedName("amount")
Double amount;
@SerializedName("location")
String location;
@SerializedName("remark")
String remark;
@SerializedName("ispaid")
String isPaid;
@SerializedName("created_at")
String createdAt;
@SerializedName("updated_at")
String updateAt;
}
Run Code Online (Sandbox Code Playgroud)
问题是REST API有时会返回一个BillItem对象数组,但有时它只是一key-value对.如何处理这种情况?
收到此响应后,一切正常,因为JSONArray获取映射到ArrayList<BillItem>-
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用Adjacency Matrix制作图表.
这是我的头文件 - graph.h -
typedef struct Node{
int vertex;
}Node_t;
typedef Node_t *Row;
typedef struct graph_t{
int noOfVertices;
Row *rowPointer;
}graph_t, *graph_p;
Run Code Online (Sandbox Code Playgroud)
这是我的定义文件 - graph.c -
graph_p createGraph(int noOfVertices){
int i,
j;
graph_p graph = (graph_p)malloc(sizeof(graph_t));
graph->noOfVertices = noOfVertices;
graph->rowPointer = (Row *)malloc(noOfVertices * sizeof(Row));
fprintf(stdout, "\nValue of graph->rowPointer: %p\n", graph->rowPointer);
for(i = 0; i < noOfVertices; i++){
Row r = (Node_t *)malloc(noOfVertices * sizeof(Node_t));
fprintf(stdout, "Value of r: %p\n", r);
graph->rowPointer[i] = &r;
fprintf(stdout, "Value …Run Code Online (Sandbox Code Playgroud)