首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法更新Android的Card - Cardslib库中显示的值

无法更新Android的Card - Cardslib库中显示的值
EN

Stack Overflow用户
提问于 2015-09-16 11:46:54
回答 1查看 80关注 0票数 2

我是从Github的Cardslib库实现CardWithList设计的。图书馆链接:卡迪斯利布

我面临的问题是我不能更新卡值--这是代码GetStat.java

代码语言:javascript
复制
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);
    }
}
}

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-16 12:13:27

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

代码语言:javascript
复制
//Update the array inside the card
ArrayList<MyObject> objs = new ArrayList<WeatherObject>();
//.....
getLinearListAdapter().addAll(objs);

就你而言:

代码语言:javascript
复制
public void updateList(.....){

    CommonGateway usersobj= new CommonGateway(this);

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

}

更多信息:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32607733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档