它的工作,我會在這裏分享代碼,因爲我做了一些小改動。 的listalayout.xml只是,我希望出現在每行的組件(包括numberPicker)
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// We came from the scanning activity; the return intent contains a RESULT_EXTRA key
// whose value is an ArrayList of BarcodeResult objects that we found while scanning.
// Get the list of objects and add them to our list view.
if (resultCode == RESULT_OK)
{
ArrayList<BarcodeResult> barcodes = data.getParcelableArrayListExtra(BarcodeScanActivity.RESULT_EXTRA);
if (barcodes != null)
{
for (int i =0;i<barcodes.size();i++)
{
bcResultArray.add(barcodes.get(i).barcodeString);
}
ListView barcodeList = (ListView) findViewById(R.id.listView1);
ListAdapter customAdapter = new MyXYZAdapter(this, R.layout.listalayout, bcResultArray);
barcodeList.setAdapter(customAdapter);
}
}
}
public class MyXYZAdapter extends ArrayAdapter<String> {
private final List<String> list;
public MyXYZAdapter(Context context, int resource, List<String> items) {
super(context, resource, items);
list = items;
}
//other stuff
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.listalayout, null);
}
TextView tv1 = (TextView) v.findViewById(R.id.lltitulo);
tv1.setText(list.get(position));
NumberPicker np = (NumberPicker) v.findViewById(R.id.numberPicker1);
np.setMaxValue(999);
np.setMinValue(0);
np.setValue(1);
return v;
}
//other stuff
}
你說的numberpicker是什麼意思? – Pavlos
我需要像這樣的列表視圖http://img706.imageshack.us/img706/7056/nti8.jpg – Igor
您必須爲列表視圖創建自己的適配器,然後相應地填充它!它不會很容易做到適配器! 你可以在這裏學習基礎知識http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ – Pavlos