2015-09-16 1 views
2

J'implémente la conception CardWithList de la bibliothèque Cardslib de Github. Link Library: Cardslib GithubImpossible de mettre à jour la valeur affichée dans la carte - Bibliothèque Cardslib pour Android

Le problème auquel est confronté im est que je ne peux pas mettre à jour les valeurs des cartes Voici le code 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); 
    } 
} 
} 

je veux mettre à jour les valeurs de carte après la AsyncTask complète

Répondre

1

Vous pouvez accéder aux données à l'intérieur de ce type de carte en utilisant:

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

Dans votre cas:

public void updateList(.....){ 

    CommonGateway usersobj= new CommonGateway(this); 

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

} 

Plus d'infos: