我有一個活動,我想顯示一個ListView像datagrid。數組列表ITransducer []是動態的,我想使用數組列表來生成列表視圖的列。ListView佈局生成動態可以編程方式顯示
ListView
ITransducer1 | ITransducer2 | ITransducer3
aa1 | aa2 | AA3
我不得不重寫getView()方法,但我必須加載一個佈局列表視圖這樣 視圖= vi.inflate(R.layout.historical_data_details_item,NULL);
我可以通過ITransducer []生成動態列表視圖佈局嗎?
public class HistoricalDataDetailsActivity extends Activity {
ListView lvDetails;
Context context;
IDAL idal;
TransducerFactory tFactory;
@Override
protected void onCreate(Bundle savedInBundleState) {
super.onCreate(savedInBundleState);
setContentView(R.layout.historical_data_details);
context = this;
tFactory = new TransducerFactory();
lvDetails = (ListView) findViewById(R.id.lvDetails);
}
@Override
protected void onStart() {
super.onStart();
ITransducer[] its = new ITransducer[]{
new AbsTransducer("aa1", TransducerType.AirPressure),
new AbsTransducer("aa2", TransducerType.AirPressure),
new AbsTransducer("aa3", TransducerType.Temperature)
};
// ListViewItemAdapter適配器=新ListViewItemAdapter(此,R.layout.historical_data_details_item,其); // lvDetails.setAdapter(adapter); }
class ListViewItemAdapter extends ArrayAdapter<ITransducer>{
boolean HasHeader = false;
public ListViewItemAdapter(Context context, int textViewResourceId, ITransducer[] objects){
super(context, textViewResourceId, objects);
}
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
if(view == null){
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.historical_data_details_item, null);
TextView tvDate = new TextView(context);
tvDate.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
tvDate.setText("DateTime");
LinearLayout layout = (LinearLayout) view.findViewById(R.id.tLayout);
layout.addView(tvDate);
view = layout;
}else
view = convertView;
return view;
}
}
}
要顯示aa1 | aa2 | aa3像coloums? – Ankit
肯定的,但列是由SQLite表 – Whistler