小编yad*_*_vi的帖子

不调用自定义适配器getView()方法

这是片段的代码,我在其中为列表设置自定义适配器.

没有错误,但是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)

android android-adapter

36
推荐指数
2
解决办法
5万
查看次数

不调用自定义适配器getview

我有一个带有a 的自定义适配器,ListFragmentgetView()根本没有调用适配器.

这是适配器的样子 -

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)

android android-adapter android-listfragment

12
推荐指数
1
解决办法
2万
查看次数

fgets()的返回值

我最近刚开始工作I/OC.这是我的问题 -
我有一个文件,我从中读取了我的输入.然后我用来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)

c io fgets

10
推荐指数
1
解决办法
4万
查看次数

Java的SwingWorker和Android AsyncTask之间的差异

我正在比较Swing SwingWorker和Android的AsyncTask类之间的差异.虽然Android有一个主线程/ UI线程,然后产生一个后台线程(使用AsyncTask),SwingWorker有三个涉及的线程 -

  • 当前线程
  • 工人线程
  • 事件派遣线程.

然后我也发现了声明(在文档中) -

通常,Current线程是Event Dispatch Thread.

现在,这是什么意思?

这是否意味着Swing也只有1个线程 - 主线程甚至事件都在同一个线程上接收或者 它对于不同的JVM实现是否不同?

java swing android swingworker android-asynctask

6
推荐指数
1
解决办法
1026
查看次数

SeekBar的onProgressChanged()被调用两次

我创建了一个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)

android seekbar preference

5
推荐指数
1
解决办法
7326
查看次数

解析Android中的资源文件时出现XmlPullParserException

我正在尝试解析我在资源文件夹中的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)

这是我得到的例外: …

android xmlpullparser

4
推荐指数
1
解决办法
3932
查看次数

使用fscanf()使用C解析逗号分隔文件

我有一个数据类似的文件 -

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个这样的字符串.
我哪里错了?

c file-io scanf

4
推荐指数
1
解决办法
1万
查看次数

ScrollView/NestedScrollView中的RecyclerView无法正确滚动

我的布局有一个CardView和一个FloatingActionButton相关的布局.下面有一个回复列表CardView(这是一个RecyclerView).有时CardViews'高度大于屏幕,所以我已经习惯layout_height="wrap_content"CardView将整个LinearLayout内部包裹起来ScrollView.

但是,这会导致问题(因为它是一个内部的滚动视图ScrollView),同时滚动项目RecyclerView.正如在发布的一些问题答案中所建议的那样,我已经使用了NestedScrollViewandroid: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)

android scrollview android-recyclerview

4
推荐指数
2
解决办法
1万
查看次数

将源添加到Android Studio项目中的jar库

我有一个应用程序,它使用第三方库 - 简单的Facebook - 来访问Facebook Graph API.此第三方库本身在内部使用 Facebook SDK作为库.


我对这个问题很少 -

  • 由于图书馆是第三方,它是否也应该包含在APK中?
    范围

    如果是这样,那么它会出错. 范围例外
    注意:有人也可以解释其含义Compile, Provided, APK, Test compile, Debug compile and Release compile.

  • 我的项目结构是这样的 -
    第1部分
    第2部分
    第3部分

    项目结构是正确的还是Facebook SDK根本不应包括在内.

我们如何将源/文档添加到库中?

我们可以将源文件/ jar附加到eclipse中的库jar(如本例所示).这使得阅读使用的文档非常容易imports.Android Studio中有类似的东西吗?

eclipse android gradle libraries android-studio

2
推荐指数
1
解决办法
3698
查看次数

当回复有时是一个对象而有时是一个数组时,如何在使用改进时解析JSON回复?

我正在使用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)

java json rx-java retrofit

2
推荐指数
1
解决办法
1361
查看次数

无法在C中分配指针

我正在使用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)

c pointers graph

0
推荐指数
1
解决办法
132
查看次数