我是android的新手,我正在使用数组适配器实现自定义列表视图,在我的arraylist中我有10个不同的值但是我将这个值设置为listview它只显示最后一个view.i非常混乱请清除我的怀疑
这是我的数组适配器
package com.example.pfdv2;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class ProductAdapter extends ArrayAdapter<Product> {
Context context;
int layoutResourceId;
Product data[] = null;
private static final String TAG = "CustomAdapter";
private static int convertViewCounter = 0;
public ProductAdapter(Context context, int layoutResourceId,Product[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ProductHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ProductHolder();
holder.txtvCode = (TextView)row.findViewById(R.id.txtvCode);
holder.txtvBrand = (TextView)row.findViewById(R.id.txtvBrand);
holder.txtvQuantity = (TextView)row.findViewById(R.id.txtvQuantity);
holder.txtvName = (TextView)row.findViewById(R.id.txtvName);
holder.txtvPriceC = (TextView)row.findViewById(R.id.txtvPriceC);
holder.txtvPriceC2 = (TextView)row.findViewById(R.id.txtvPriceC2);
holder.txtvPointsC = (TextView)row.findViewById(R.id.txtvPointsC);
// holder.txtvPointsCC = (TextView)row.findViewById(R.id.txtvPointsCC);
holder.txtvPriceU = (TextView)row.findViewById(R.id.txtvPriceU);
holder.txtvPriceU2 = (TextView)row.findViewById(R.id.txtvPriceU2);
holder.txtvPointsU = (TextView)row.findViewById(R.id.txtvPointsU);
// holder.txtvPointsUU = (TextView)row.findViewById(R.id.txtvPointsUU);
row.setTag(holder);
}
else
{
holder = (ProductHolder)row.getTag();
}
Product product = data[position];
holder.txtvCode.setText(Product.getProductID());
holder.txtvBrand.setText(Product.getProductType());
holder.txtvQuantity.setText(Product.BrandID());
holder.txtvName.setText(Product.getProductName());
double j = Product.getCartonPrice();
String jresult = new Double(j).toString();
holder.txtvPriceC.setText(jresult);
double k = Product.getCartonPoints();
String kresult = new Double(k).toString();
holder.txtvPriceC2.setText(kresult);
double l = Product.getCTNAvail();
String lresult = new Double(l).toString();
holder.txtvPointsC.setText(lresult);
// holder.txtvPointsCC.setText(product.get());
double m = Product.getUnitPrice();
String mresult = new Double(m).toString();
holder.txtvPriceU.setText(mresult);
double n = Product.getUnitPoints();
String nresult = new Double(n).toString();
holder.txtvPriceU2.setText(nresult);
double o = Product.getUnitAvail();
String oresult = new Double(o).toString();
holder.txtvPointsU.setText(oresult);
// holder.txtvPointsUU.setText(product.getUnitAvail());
return row;
}
static class ProductHolder
{
ImageView imgIcon;
TextView txtvCode,txtvBrand,txtvQuantity,txtvName,txtvPriceC,txtvPriceC2,txtvPointsC,
txtvPointsCC,txtvPriceU,txtvPriceU2,txtvPointsU,txtvPointsUU;
}
}
以下是我从活动中传递的方式
ackage com.example.pfdv2;
import java.util.ArrayList;
import java.util.List;
import org.ksoap2.serialization.SoapObject;
import com.example.pfdv2.ProductAdapter.ProductHolder;
import android.R.array;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.app.ActionBar;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
public class Page_ListRowP extends ListActivity {
private static final String ProductAdapter = null;
private TextView text;
private TextView textVitems,txtProductName,txtBrandID,txtProductID,txtProductType,txtCartonP,txtCPoints, txtUAvail, txtUPrice, txtCTNA, txtUPoints;
private TextView quantity,statusTV1;
Button btn;
private List<String> listValues;
String name;
int t=WsSearch.total;
Boolean SearchStatus = WsSearch.SearchStatus;
ListView lstClientes = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.Search);
setContentView(R.layout.page_list);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("lightgray"));
getActionBar().setBackgroundDrawable(colorDrawable);
text = (TextView) findViewById(R.id.mainText);
Product product_data[] = new Product[]
{
new Product()
};
ProductAdapter adapter = new ProductAdapter(this,
R.layout.row_products, product_data);
setListAdapter(adapter);
}
显示数据但仅显示最后一部分。我如何展示所有价值观......
Thankssssss
答案 0 :(得分:0)
看起来你的product_data数组只有一个项目。它只显示一个数据作为listitem。你想要实现的是什么?