私はAndroidで初めてで、カスタムリストビューに取り組んでおり、完全に機能しますが、リストの詳細を表示するために単一のリストをクリックすると、最後のリストの詳細のみが表示されるたびに問題が発生します。onItemClick メソッド内では、最後の請求書 ID のみが渡されます...コードは次のとおりです
try {
//*** Getting Array of Attributes
attributes = jsonreturn.getJSONObject(TAG_ATTRIBUTE);
String status = attributes.getString(TAG_VALIDCODE);
JSONObject invoices = jsonreturn.getJSONObject(TAG_INVOICELIST);
JSONArray invoice = invoices.getJSONArray(TAG_INVOICE);
if(status.equals("200")){
// looping through All Invoice
for(int i = 0; i < invoice.length(); i++)
{
JSONObject c = invoice.getJSONObject(i);
//***** Storing each JSON item in variable
JSONObject client = c.getJSONObject(TAG_CLIENT);
String organization = client.getString(TAG_ORGANIZATION);
String invoiceno = c.getString(TAG_ID);
String date = c.getString(TAG_DATE);
String currency = c.getString(TAG_CURRENCY);
String outstanding = c.getString(TAG_OUTSTANDING);
String invoice_status = c.getString(TAG_STATUS);
invoice_id = c.getString(TAG_INVOICE_ID);
//**** creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
//*** adding each child node to HashMap key => value
map.put(TAG_ORGANIZATION, organization);
map.put(TAG_ID, invoiceno);
map.put(TAG_DATE, date);
map.put(TAG_CURRENCY, currency);
map.put(TAG_OUTSTANDING, outstanding);
map.put(TAG_STATUS, invoice_status);
map.put(TAG_INVOICE_ID, invoice_id);
//**** adding HashList to ArrayList
invoiceList.add(map);
}
}
else{
Toast.makeText(this, "Invalid Details", 1000).show(); }
}
catch (JSONException e)
{
e.printStackTrace();
}
/**
Updating parsed JSON data into ListView
* */
InvoiceListAdapter invoiceadapter = new InvoiceListAdapter(this, invoiceList);
mListView.setAdapter(invoiceadapter);
//****** Launching new screen on Selecting Single ListItem
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
// getting values from selected ListItem
//--String date = ((TextView) view.findViewById(R.id.date)).getText().toString();
//--String status = ((TextView) view.findViewById(R.id.invoicestatus)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(), PreviewInvoice.class);
in.putExtra("myinvoiceid", invoice_id);
in.putExtra("uniquetoken", tokenid);
//-- in.putExtra(TAG_DATE, date);
//---in.putExtra(TAG_STATUS, status);
startActivity(in);
}
});
私の InvoiceList アダプタ クラス コード
public class InvoiceListAdapter extends BaseAdapter {
//--private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public InvoiceListAdapter(ManageInvoice manageInvoice, ArrayList<HashMap<String, String>> invoiceList) {
//-- activity = manageInvoice;
data=invoiceList;
inflater = (LayoutInflater)manageInvoice.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
if(null==data){
return 0;
}
return data.size();
}
public Object getItem(int position) {
if(null==data || data.size()<=position){
return null;
}
return data.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.invoice_list, null );
TextView title = (TextView)vi.findViewById(R.id.organization);
TextView invoiceId = (TextView)vi.findViewById(R.id.invoice_id);
TextView date = (TextView)vi.findViewById(R.id.date);
TextView currency = (TextView)vi.findViewById(R.id.currency);
TextView currencyvalue = (TextView)vi.findViewById(R.id.outstanding);
TextView status = (TextView)vi.findViewById(R.id.invoice_status);
// ImageView thumb_image=(ImageView)vi.findViewById(R.id.invoice_status);
HashMap<String, String> Invoice = new HashMap<String, String>();
Invoice = data.get(position);
// Setting all values in listview
title.setText(Invoice.get(ManageInvoice.TAG_ORGANIZATION));
invoiceId.setText(Invoice.get(ManageInvoice.TAG_ID));
date.setText(Invoice.get(ManageInvoice.TAG_DATE));
currency.setText(Invoice.get(ManageInvoice.TAG_CURRENCY));
currencyvalue.setText(Invoice.get(ManageInvoice.TAG_OUTSTANDING));
status.setText(Invoice.get(ManageInvoice.TAG_STATUS));
return vi;
}
public JSONArray get(int position) {
// TODO Auto-generated method stub
return null;
}
}