Java tutorial
package me.chenjiayang.myleancloud; import android.content.Intent; import android.os.Handler; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleAdapter; import com.avos.avoscloud.AVException; import com.avos.avoscloud.AVObject; import com.avos.avoscloud.AVQuery; import com.avos.avoscloud.AVUser; import com.avos.avoscloud.FindCallback; import com.jude.swipbackhelper.SwipeBackHelper; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import me.chenjiayang.myleancloud.util.ToastUtil; public class CarInfoActivity extends AppCompatActivity { private ListView mListView; private SimpleAdapter simpleAdapter; private List<AVObject> carlist = null; // private ArrayList<HashMap<String, Object>> item = new ArrayList<>(); private Bundle bundle; private Bundle bundle_id; // private SwipeRefreshLayout swipeRefreshLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.carinfo); SwipeBackHelper.onCreate(this); SwipeBackHelper.getCurrentPage(this).setSwipeRelateEnable(true); //? init(); // refresh(); /** * * ??LogoidR.id.home */ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); } public void setAdapter() { mListView = (ListView) this.findViewById(R.id.listview); //??SimpleAdapter simpleAdapter = new SimpleAdapter(this, item, R.layout.activity_car_info, new String[] { "itemTitle", "itemTag", "itemPhoto", "itemSummary" }, new int[] { R.id.title, R.id.ifNowDrivingTag, R.id.photograph, R.id.summary }); //SimpleAdapterListView mListView.setAdapter(simpleAdapter); } public ArrayList<HashMap<String, Object>> getItem() { return item; } private void init() { final int[] resImags = { R.drawable.aodilogo, R.drawable.mashaladi, R.drawable.dazhong, R.drawable.baoma, R.drawable.benchi, R.drawable.fute, R.drawable.fengtian, R.drawable.yingfeinidi, R.drawable.bentian, R.drawable.biyadi, R.drawable.nisang, R.drawable.bieke, R.drawable.mazida, R.drawable.leikesasi, R.drawable.woerwo, R.drawable.xuetielong, R.drawable.qirui, R.drawable.sanling, R.drawable.biaozhi, R.drawable.dongfeng, R.drawable.xiandai, R.drawable.qiya, R.drawable.baoshijie, R.drawable.lanbojini, R.drawable.falali, R.drawable.kaidilake, R.drawable.hanma, R.drawable.luhu, R.drawable.yiqi, R.drawable.mading, R.drawable.changcheng, R.drawable.changan, R.drawable.jili, R.drawable.jeep, R.drawable.kelaisile, R.drawable.nocar }; // AVQuery<AVObject> query = new AVQuery<>("Car"); query.whereEqualTo("currUserID", AVUser.getCurrentUser().getObjectId()) .findInBackground(new FindCallback<AVObject>() { @Override public void done(List<AVObject> list, AVException e) { carlist = list; for (int i = 0; i < carlist.size(); i++) { HashMap<String, Object> map = new HashMap<>(); String carname = carlist.get(i).get("CarName").toString(); String carsummary = "?" + carlist.get(i).get("License_plate_number").toString() + "\n" + "??" + carlist.get(i).get("Engine_no").toString() + "\n" + "" + carlist.get(i).get("mileage").toString() + "\n" + "?" + carlist.get(i).get("Amount_of_gasoline").toString() + "%\n" + "?" + carlist.get(i).get("transmission").toString(); map.put("itemTitle", carname); if (carlist.get(i).getObjectId().equals(AVUser.getCurrentUser().get("NowDriving"))) { map.put("itemTag", ">>"); } else { map.put("itemTag", ""); } switch (carname) { case "": map.put("itemPhoto", resImags[0]); break; case "": map.put("itemPhoto", resImags[1]); break; case "": map.put("itemPhoto", resImags[2]); break; case "?": map.put("itemPhoto", resImags[3]); break; case "": map.put("itemPhoto", resImags[4]); break; case "?": map.put("itemPhoto", resImags[5]); break; case "": map.put("itemPhoto", resImags[6]); break; case "?": map.put("itemPhoto", resImags[7]); break; case "": map.put("itemPhoto", resImags[8]); break; case "": map.put("itemPhoto", resImags[9]); break; case "": map.put("itemPhoto", resImags[10]); break; case "": map.put("itemPhoto", resImags[11]); break; case "": map.put("itemPhoto", resImags[12]); break; case "?": map.put("itemPhoto", resImags[13]); break; case "": map.put("itemPhoto", resImags[14]); break; case "?": map.put("itemPhoto", resImags[15]); break; case "": map.put("itemPhoto", resImags[16]); break; case "?": map.put("itemPhoto", resImags[17]); break; case "": map.put("itemPhoto", resImags[18]); break; case "": map.put("itemPhoto", resImags[19]); break; case "": map.put("itemPhoto", resImags[20]); break; case "": map.put("itemPhoto", resImags[21]); break; case "??": map.put("itemPhoto", resImags[22]); break; case "?": map.put("itemPhoto", resImags[23]); break; case "": map.put("itemPhoto", resImags[24]); break; case "": map.put("itemPhoto", resImags[25]); break; case "?": map.put("itemPhoto", resImags[26]); break; case "": map.put("itemPhoto", resImags[27]); break; case "": map.put("itemPhoto", resImags[28]); break; case "?": map.put("itemPhoto", resImags[29]); break; case "": map.put("itemPhoto", resImags[30]); break; case "": map.put("itemPhoto", resImags[31]); break; case "?": map.put("itemPhoto", resImags[32]); break; case "Jeep": map.put("itemPhoto", resImags[33]); break; case "": map.put("itemPhoto", resImags[34]); break; default: map.put("itemPhoto", resImags[35]); break; } map.put("itemSummary", carsummary); item.add(map); } setAdapter(); final class ListItemClickListener implements AdapterView.OnItemClickListener { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //?bundle bundle_id = new Bundle(); bundle_id.putString("ObjectId", carlist.get(position).getObjectId()); bundle = new Bundle(); bundle.putString("CarName", carlist.get(position).get("CarName").toString()); bundle.putString("License_plate_number", carlist.get(position).get("License_plate_number").toString()); bundle.putString("Engine_no", carlist.get(position).get("Engine_no").toString()); bundle.putString("mileage", carlist.get(position).get("mileage").toString()); bundle.putString("Amount_of_gasoline", carlist.get(position).get("Amount_of_gasoline").toString()); bundle.putString("Engine_situation", carlist.get(position).get("Engine_situation").toString()); bundle.putString("CarLight", carlist.get(position).get("CarLight").toString()); bundle.putString("transmission", carlist.get(position).get("transmission").toString()); Intent intent = new Intent(CarInfoActivity.this, CarItemActivity.class); intent.putExtra("carlist_elem", bundle); intent.putExtra("car_ObjectId", bundle_id); startActivity(intent); } } // item? mListView.setOnItemClickListener(new ListItemClickListener()); } }); } private void refresh() { swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container); //?4 swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { // TODO Auto-generated method stub //refresh? carlist.clear(); item.clear(); init(); new Handler().postDelayed(new Runnable() { @Override public void run() { ToastUtil.show(CarInfoActivity.this, "??"); // TODO Auto-generated method stub swipeRefreshLayout.setRefreshing(false); } }, 2000); //3s } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.refresh, menu); return true; } /** * Main2Activity? * @param item * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.tool_refresh: ToastUtil.show(CarInfoActivity.this, ""); break; case android.R.id.home: this.finish(); break; } return super.onOptionsItemSelected(item); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); SwipeBackHelper.onPostCreate(this); } @Override protected void onDestroy() { super.onDestroy(); SwipeBackHelper.onDestroy(this); } }