package com.example.kun.carcarkila;
-
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
-
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.amigold.fundapter.interfaces.DynamicImageLoader;
import com.kosalgeek.android.json.JsonConverter;
import com.kosalgeek.genasync12.AsyncResponse;
import com.kosalgeek.genasync12.PostResponseAsyncTask;
import com.nostra13.universalimageloader.core.ImageLoader;
-
import java.io.Serializable;
import java.util.ArrayList;
-
public class HomeActivity extends AppCompatActivity implements AsyncResponse, AdapterView.OnItemClickListener {
final String LOG = "HomeActivity";
-
private ArrayList<Product> productList;
private ListView lvProduct;
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
-
-
-
ImageLoader.getInstance().init(UILConfig.config(HomeActivity.this)); // Do it on Application start
-
PostResponseAsyncTask taskRead = new PostResponseAsyncTask(HomeActivity.this, this);
taskRead.execute("http://10.0.2.2/carkila/product.php");
-
-
}
-
@Override
public void processFinish(String s) {
-
productList = new JsonConverter<Product>().toArrayList(s, Product.class);
-
BindDictionary<Product> dict = new BindDictionary<Product>();
-
dict.addDynamicImageField(R.id.ivImg, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return item.img;
}
}, new DynamicImageLoader() {
@Override
public void loadImage(String url, ImageView imageView) {
-
ImageLoader.getInstance().displayImage(url, imageView); // Default options will be used
}
});
dict.addStringField(R.id.tvCarModel, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Car Model: " + item.Car_Model;
}
});
dict.addStringField(R.id.tvCarType, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Car Type: " + item.Car_Type;
}
});
dict.addStringField(R.id.tvCapacity, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Capacity: " + item.Capacity;
}
});
-
FunDapter<Product> adapter = new FunDapter<>(
HomeActivity.this, productList, R.layout.layout_list, dict);
lvProduct = (ListView)findViewById(R.id.lvProduct);
lvProduct.setAdapter(adapter);
lvProduct.setOnItemClickListener(this);
}
-
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Product selectedProduct = productList.get(position);
Intent in = new Intent(HomeActivity.this, DetailActivity.class);
in.putExtra("product", (Serializable) selectedProduct);
startActivity(in);
}
}
package com.example.kun.carcarkila;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.amigold.fundapter.interfaces.DynamicImageLoader;
import com.kosalgeek.android.json.JsonConverter;
import com.kosalgeek.genasync12.AsyncResponse;
import com.kosalgeek.genasync12.PostResponseAsyncTask;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.io.Serializable;
import java.util.ArrayList;
public class HomeActivity extends AppCompatActivity implements AsyncResponse, AdapterView.OnItemClickListener {
final String LOG = "HomeActivity";
private ArrayList<Product> productList;
private ListView lvProduct;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ImageLoader.getInstance().init(UILConfig.config(HomeActivity.this)); // Do it on Application start
PostResponseAsyncTask taskRead = new PostResponseAsyncTask(HomeActivity.this, this);
taskRead.execute("http://10.0.2.2/carkila/product.php");
}
@Override
public void processFinish(String s) {
productList = new JsonConverter<Product>().toArrayList(s, Product.class);
BindDictionary<Product> dict = new BindDictionary<Product>();
dict.addDynamicImageField(R.id.ivImg, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return item.img;
}
}, new DynamicImageLoader() {
@Override
public void loadImage(String url, ImageView imageView) {
ImageLoader.getInstance().displayImage(url, imageView); // Default options will be used
}
});
dict.addStringField(R.id.tvCarModel, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Car Model: " + item.Car_Model;
}
});
dict.addStringField(R.id.tvCarType, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Car Type: " + item.Car_Type;
}
});
dict.addStringField(R.id.tvCapacity, new StringExtractor<Product>() {
@Override
public String getStringValue(Product item, int position) {
return "Capacity: " + item.Capacity;
}
});
FunDapter<Product> adapter = new FunDapter<>(
HomeActivity.this, productList, R.layout.layout_list, dict);
lvProduct = (ListView)findViewById(R.id.lvProduct);
lvProduct.setAdapter(adapter);
lvProduct.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Product selectedProduct = productList.get(position);
Intent in = new Intent(HomeActivity.this, DetailActivity.class);
in.putExtra("product", (Serializable) selectedProduct);
startActivity(in);
}
}
2 Answer(s)