i want to make a view as bellow :
for control it, i made JSON in my class variabel, this is my Activity :
public class KategoriNomorPolis extends ListActivity{
ListView lv_epolicy;
ArrayAdapter<String> adapter;
List<String> list = new ArrayList<String>();
String[][] c = new String[10][10];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.epolicy_list_polis);
adapter=new ArrayAdapter<String>(this,R.layout.list_item);
kategori_epolicy();
}
private void kategori_epolicy(){
String result=ListPolis.json_kategori;
JSONArray array=null;
try{
array= new JSONArray(result);
for (int i=0;i<array.length();i++){
JSONObject object = array.getJSONObject(i);
c[i][0] = object.getString("id_kategori");
c[i][1] = object.getString("kategori");
// adapter.insert(object.getString("kategori"), i);
System.out.println("yuhuuu");
}
lv_epolicy=(ListView)findViewById(android.R.id.list);
KategoriEpolicyAdapter adapter = new KategoriEpolicyAdapter(KategoriNomorPolis.this, array);
lv_epolicy.setAdapter(adapter);
lv_epolicy.setCacheColorHint(Color.TRANSPARENT);
}catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
I have no idea why my adapter not showing anything,i have declare my listview with lv_epolicy=(ListView)findViewById(android.R.id.list);
and nothing happen and this is my KategoriEpolicyAdapter :
public class KategoriEpolicyAdapter extends BaseAdapter{
Context context;
JSONArray array;
int count;
public KategoriEpolicyAdapter(Context context, JSONArray array){
this.context = context;
this.array = array;
this.count = array.length();
}
public int getCount() {
// TODO Auto-generated method stub
return count;
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View contentView, ViewGroup arg2) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
contentView = inflater.inflate(R.layout.epolicy_kategori, null);
ImageView img_epolicy = (ImageView)contentView.findViewById(R.id.img_epolicy);
TextView text_kategori = (TextView)contentView.findViewById(R.id.text_kategori);
String result=ListPolis.json_kategori;
try {
JSONObject object = array.getJSONObject(position);
text_kategori.setText(object.getString("kategori"));
System.out.println("bisa ga ya? ");
switch(position){
case 0:
img_epolicy.setImageResource(R.drawable.pp_icon);
break;
case 1:
img_epolicy.setImageResource(R.drawable.tertanggung_icon);
break;
case 2:
img_epolicy.setImageResource(R.drawable.dataasuransi_icon);
break;
case 3:
img_epolicy.setImageResource(R.drawable.manfaat_icon);
break;
case 4:
img_epolicy.setImageResource(R.drawable.inventaris_icon);
break;
case 5:
img_epolicy.setImageResource(R.drawable.status_icon);
break;
case 6:
img_epolicy.setImageResource(R.drawable.rekening_icon);
break;
}
} catch (Exception e) {
// TODO: handle exception
}
return contentView;
}
i hope somebody can tell me where is my fault....