使用SwipeCards和自定义适配器不显示某些值?

时间:2016-04-13 02:55:06

标签: android android-layout android-activity layout android-asynctask

我正在使用这里的Swipecards项目:https://github.com/Diolor/Swipecards我创建了一个自定义适配器,用于我自己的对象,而不是简单的ArrayAdapter,因为我需要一些额外的字段,但是,不是我的所有自定义田野正在出现在sw ..

使用以下代码,标题,公司名称和说明字段正确填充到我的卡上,而不是其他字段,即使字段在那里。调试器没有错误,一切正常,但字段没有填充数据!我错过了什么?

以下是我在活动中所做的事情:

活动的顶部:

@InjectView(R.id.frame) SwipeFlingAdapterView flingContainer;

在我的AsyncTask中:

arrayAdapter = new JobAdapter(getApplicationContext(), R.layout.jobcard,      result);
flingContainer.setAdapter(arrayAdapter);

是:结果ArrayList填充了值。

我的适配器:

public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder = null;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService((Activity.LAYOUT_INFLATER_SERVICE));

        if (row == null) {
            row = inflater.inflate(layoutResourceId, parent, false);
            //row = inflater.inflate(layoutResourceId, null);

            holder = new ViewHolder();
            holder.title = (TextView)row.findViewById(R.id.tv_jobTitle);
            holder.payrate = (TextView)row.findViewById(R.id.tv_payRate);
            holder.startdate = (TextView)row.findViewById(R.id.tv_startDate);
            holder.workinghrs = (TextView)row.findViewById(R.id.tv_duration);
            holder.location = (TextView)row.findViewById(R.id.tv_location);
            holder.companyname = (TextView)row.findViewById(R.id.tv_companyName);
            holder.description = (TextView)row.findViewById(R.id.tv_JobDesc);
            holder.equipment = (TextView)row.findViewById(R.id.tv_equipmentReq);
            holder.experience = (TextView)row.findViewById(R.id.tv_experienceReq);

            row.setTag(holder);
        } else {
            holder = (ViewHolder)row.getTag();
        }

        Job j = jobs.get(0);

        holder.title.setText(j.getJobTitle());
        holder.payrate.setText(j.getPayrate());
        holder.startdate.setText(j.getDurationStart());
        holder.workinghrs.setText(j.getWorkingHrs());
        holder.location.setText(j.getLocation());
        holder.companyname.setText("ABC Company");
        holder.description.setText(j.getDescription());
        holder.equipment.setText("Hardhat");
        holder.experience.setText("3-5 years");

        return row;
    }
    static class ViewHolder
    {
        TextView title;
        TextView payrate;
        TextView startdate;
        TextView workinghrs;
        TextView location;
        TextView companyname;
        TextView description;
        TextView equipment;
        TextView experience;
    }

最后,我的jobcard.xml布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:padding="20dp">

    <LinearLayout
        android:id="@+id/mainCardLayout"
        android:layout_width="match_parent"
        android:layout_height="340dp"
        android:layout_gravity="center"
        android:orientation="vertical"
        android:weightSum="1"
        android:background="#ffffff">

        <TextView
            android:id="@+id/tv_jobTitle"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:textStyle="bold"
            android:textSize="16sp"
            android:textColor="#474747"
            android:textAlignment="center"
            tools:text="Cement Pouring Guy"
            android:layout_gravity="center_horizontal"/>

        <TextView
            android:id="@+id/tv_companyName"
            android:background="#ffffff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="14sp"
            android:textColor="#474747"
            android:textAlignment="center"
            tools:text="ABC Company"
            android:layout_gravity="center_horizontal" />

        <LinearLayout
            android:id="@+id/cardHeader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="20dp">

            <TextView
                android:id="@+id/tv_experienceReq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginLeft="10dp"
                tools:text="3-5 years" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/tv_location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                tools:text="Langley, BC" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1" />

            <TextView
                android:id="@+id/tv_payRate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginRight="10dp"
                tools:text="125/day" />

        </LinearLayout>

        <TextView
            android:id="@+id/tv_JobDesc"
            android:textSize="14sp"
            android:textColor="#474747"
            android:background="#f3f3f3"
            tools:text="Pour Cement, Mix Cement, Level Cement and go pick up cement bags."
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:padding="15dp" />

        <LinearLayout
            android:id="@+id/additionalInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <TextView
                android:id="@+id/tv_startDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginLeft="10dp"
                tools:text="June 1, 2016" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/tv_duration"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                tools:text="8h" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                />

            <TextView
                android:id="@+id/tv_equipmentReq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:layout_marginRight="10dp"
                tools:text="Hardhat" />

        </LinearLayout>

    </LinearLayout>

    <View
        android:id="@+id/item_swipe_left_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="20dp"
        android:background="#A5F" />

    <View
        android:id="@+id/item_swipe_right_indicator"
        android:alpha="0"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_margin="20dp"
        android:layout_gravity="right"
        android:background="#5AF" />

</FrameLayout>

感谢您的帮助!

0 个答案:

没有答案