所以,到目前为止,我建立了一个这样的 json 对象列表
public class list extends ListActivity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
Intent i = getIntent();
String snopel = i.getStringExtra("nopel");
String snama = i.getStringExtra("nama");
String salamat = i.getStringExtra("alamat");
String sgolongan = i.getStringExtra("golongan");
TextView tx_nopel = (TextView)findViewById(R.id.l_nopel);
TextView tx_nama= (TextView)findViewById(R.id.l_nama);
TextView tx_alamat = (TextView)findViewById(R.id.l_alamat);
TextView tx_golongan = (TextView)findViewById(R.id.l_golongan);
tx_nopel.setText(snopel);
tx_nama.setText(snama);
tx_alamat.setText(salamat);
tx_golongan.setText(sgolongan);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("nopel", snopel));
ArrayList<HashMap<String, String>> lr = new ArrayList<HashMap<String, String>>();
JSON json_lr = new JSON();
JSONObject jobj_lr = json_lr.getJSON("http://10.0.2.2/KP/pdam/listtagihan.php", pairs);
try {
int length = jobj_lr.getInt("panjang");
for(int n = 1; n <= length; n++){
String m = Integer.toString(n);
JSONObject row = jobj_lr.getJSONObject(m);
String snomor = row.getString("nomor");
String sbulan = row.getString("bulan");
String stahun = row.getString("tahun");
String stagihan = "Rp. " + row.getString("tagihan");
HashMap<String, String> rek = new HashMap<String, String>();
rek.put("nomor", snomor);
rek.put("bulan", sbulan);
rek.put("tahun", stahun);
rek.put("tagihan", stagihan);
lr.add(rek);
}
} catch (JSONException e) {
e.printStackTrace();
}
ListAdapter adapter_lr = new SimpleAdapter(this, lr, R.layout.list_data,
new String[]{"nomor","bulan","tahun","tagihan"},
new int[]{R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4});
setListAdapter(adapter_lr);
ListView lv_lr = getListView();
lv_lr.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Intent i = new Intent(list.this, rincian.class);
i.putExtra("nomor", ((TextView)view.findViewById(R.id.textView1)).getText().toString());
startActivity(i);
}
});
}
}
这将在一个列表活动中显示一个列表视图,但我想知道我是否可以在 1 个列表活动中创建 2 个自定义列表视图,但我不知道如何
我认为这是不可能的,因为在 listactivity 中,我们必须设置只能像这样选择 1 个列表适配器的适配器setListAdapter(adapter_lr);
但我想确定这是真的吗?
提前致谢。