我正在从 Github 的库中实现CardWithList
设计。Cardslib
图书馆链接:Cardslib Github
我想对left in animation
列表中的元素执行
private void setLeftAdapter() {
AnimationAdapter animCardArrayAdapter = new SwingLeftInAnimationAdapter(mCardArrayAdapter);
animCardArrayAdapter.setAbsListView(mListView);
mListView.setExternalAdapter(animCardArrayAdapter, mCardArrayAdapter);
}
我不知道在哪里放置此代码,并且我的 java 代码中没有 mCardArrayAdapter 和 mListView
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 org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardArrayAdapter;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.prototypes.CardWithList;
import it.gmariotti.cardslib.library.view.CardListView;
public class GetStat extends CardWithList {
long musers;
long mclicks;
long mbanner;
long mptc;
long mtickets;
double mwithdraw;
double mfunds;
double minvested;
CommonGateway usersobj, clickobj;
private void updateResult(String jsonResp) {
try {
JSONObject jsonResponse = new JSONObject(jsonResp);
musers = jsonResponse.getLong("users");
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");
CommonGateway usersobj = new CommonGateway(this);
//Set the value..
usersobj.SetData("Users", R.drawable.usersico, musers);
getLinearListAdapter().add(usersobj);
clickobj.SetData("Clicks", R.drawable.clicks24, mclicks);
getLinearListAdapter().add(clickobj);
} 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=234234df&sub=stats")
.ensureSuccess()
.asString().getBody();
return response;
}
}
public GetStat(Context context) {
super(context);
new SimplePoster().execute();
}
@Override
protected CardHeader initCardHeader() {
CardHeader header = new CardHeader(getContext(), R.layout.cardheader);
//header.setTitle("Statistics");
return header;
}
@Override
protected void initCard() {
//Create a CardHeader
CardHeader header = new CardHeader(getContext());
//Set the header title
header.setTitle("Statistics");
setUseEmptyView(false);
setUseProgressBar(true);
updateProgressBar(true, true);
addCardHeader(header);
}
@Override
protected List<ListObject> initChildren() {
//Init the list
List<ListObject> mObjects = new ArrayList<ListObject>();
usersobj = new CommonGateway(this);
clickobj = new CommonGateway(this);
bannerobj = new CommonGateway(this);
fundobj = new CommonGateway(this);
withdrawobj = new CommonGateway(this);
ptcobj = new CommonGateway(this);
ticketsobj = new CommonGateway(this);
investedobj = 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);
}
}
}
MainActivity.java
import android.app.ActionBar;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import it.gmariotti.cardslib.library.internal.CardArrayAdapter;
import it.gmariotti.cardslib.library.view.CardListView;
import it.gmariotti.cardslib.library.view.CardView;
public class MainActivity extends AppCompatActivity {
GetStat card;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.action_main);
getSupportActionBar().setTitle("GPT Analytics");
setContentView(R.layout.activity_main);
card= new GetStat(getApplicationContext());
card.updateProgressBar(false, false);
card.init();
//Set card in the cardView
CardView cardView = (CardView) findViewById(R.id.statcard);
cardView.setCard(card);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
Intent intent=new Intent(this,searchactivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
我也无法设置加载进度条