2

我正在从 Github 的 Cardslib 库中实现 CardWithList 设计。图书馆链接:Cardslib Github

我面临的问题是我无法更新卡值这是代码 GetStat.java

import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.prototypes.CardWithList;

public class GetStat extends CardWithList {
long musers;
long mclicks;
long mbanner;
long mptc;
long mtickets;
double mwithdraw;
double mfunds;
double minvested;
CommonGateway usersobj;

private void updateResult(String jsonResp) {

    try {
        JSONObject jsonResponse = new JSONObject(jsonResp);
        musers = jsonResponse.getLong("users");
        usersobj.numbers=String.valueOf(musers);
        Toast.makeText(getContext(), "Complete"+musers, Toast.LENGTH_SHORT).show();
        mclicks = jsonResponse.getLong("clicks");
        mbanner = jsonResponse.getLong("banner");
        mptc = jsonResponse.getLong("ptc");
        mtickets = jsonResponse.getLong("tickets");

        mwithdraw = jsonResponse.getDouble("withdraw");
        mfunds = jsonResponse.getDouble("funds");
        minvested = jsonResponse.getDouble("invested");

    } catch (Exception e) {

    }
}

public class SimplePoster extends AsyncTask<Void, Void, String> {
    @Override
    protected void onPostExecute(String s) {
        updateResult(s);


    }

    @Override
    protected String doInBackground(Void... params) {
        Webb webb = Webb.create();
        String response = webb.post("http://example.net/api/?action=site_admin&type=json&api=gbh&sub=stats")
                .ensureSuccess()
                .asString().getBody();
        return response;
    }
}

public GetStat(Context context,Values v) {
    super(context);

}

@Override
protected CardHeader initCardHeader() {
    CardHeader header = new CardHeader(getContext(), R.layout.header);
    header.setTitle("Statistics"); //should use R.string.
    return header;
}

@Override
protected void initCard() {

}

@Override
protected List<ListObject> initChildren() {

    //Init the list
    List<ListObject> mObjects = new ArrayList<ListObject>();
     usersobj= new CommonGateway(this);

   usersobj.SetData("Users", R.drawable.usersico,musers);
    mObjects.add(usersobj);

    return mObjects;

}

@Override
public View setupChildView(int i, ListObject listObject, View view, ViewGroup viewGroup) {

    TextView title = (TextView) view.findViewById(R.id.cardtitle);
    ImageView icon = (ImageView) view.findViewById(R.id.cardimage);
    TextView numbers = (TextView) view.findViewById(R.id.cardnumbers);

    CommonGateway gatewayObject= (CommonGateway)listObject;
    icon.setImageResource(gatewayObject.icon);
    title.setText(gatewayObject.title);
    numbers.setText(gatewayObject.numbers);

    return view;
}



@Override
public int getChildLayoutId() {
    return R.layout.cardmain;
}
public class CommonGateway extends DefaultListObject {

    String title="null";
    String numbers="null";
    int icon=0;
    public CommonGateway(Card parentCard) {
        super(parentCard);


    }
    public void SetData(String title,int icon,long numbers)
    {
        this.title=title;
        this.icon=icon;
        this.numbers=String.valueOf(numbers);
    }
    public void SetData(String title,int icon,double numbers)
    {
        this.title=title;
        this.icon=icon;
        this.numbers=String.valueOf(numbers);
    }
}
}

我想在异步任务完成后更新卡值

4

1 回答 1

1

您可以使用以下方式访问此类卡内的数据:

//Update the array inside the card
ArrayList<MyObject> objs = new ArrayList<WeatherObject>();
//.....
getLinearListAdapter().addAll(objs);

在你的情况下:

public void updateList(.....){

    CommonGateway usersobj= new CommonGateway(this);

    //Set the value..
   usersobj.SetData("Users", R.drawable.usersico,musers);
   getLinearListAdapter().add(usersobj);

}

更多信息:

于 2015-09-16T12:13:27.813 回答