gpt4 book ai didi

android - 一个列表 Activity 中的两个自定义 ListView

转载 作者:行者123 更新时间:2023-11-29 14:53:42 25 4
gpt4 key购买 nike

到目前为止,我构建了一个像这样的 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);
}

});
}
}

这将在一个列表 Activity 中显示一个 ListView ,但我想知道我是否可以在 1 个列表 Activity 中制作 2 个自定义 ListView ,但我不知道该怎么做

我认为这是不可能的,因为在 listactivity 中我们必须像这样设置只能选择 1 个列表适配器的适配器 setListAdapter(adapter_lr);

但我想确定这是真的吗?

提前致谢。

最佳答案

为什么一个 Activity 需要两个 ListView ?

如果您想要两个 ListView ,那么您可以扩展 Activity在布局文件中添加两个 ListView 。

现在,

ListView listView1=(ListView)findViewById(R.id.listview1);
ListView listView2=(ListView)findViewById(R.id.listview2);

关于android - 一个列表 Activity 中的两个自定义 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11288675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com