Tôi muốn làm cho một listview trông giống như kiểm soát datagrid trong android.All cột được tạo ra bởi code-behand đó là đoạn mã dynamic.My có thể xây dựng thành công nhưng listview không hiển thị như tôi mong đợi.Điều gì là sai với nó?Tôi có thể chèn một cột trong listview vào thời gian chạy không?
@Override
public View getView(int position, View convertView, ViewGroup parentView) {
ViewHolder holder = null;
if (convertView == null) {
synchronized (MainActivity.this) {
convertView = mInflater.inflate(id_row_layout, null);
holder = new ViewHolder();
//I had add an textView to the convertView,but it not show
LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.rLayout);
TextView tx = new TextView(context);
tx.setText("ads");
layout.addView(tx);
MyHScrollView scrollView1 = (MyHScrollView) convertView
.findViewById(R.id.horizontalScrollView1);
holder.scrollView = scrollView1;
holder.txt1 = (TextView) convertView
.findViewById(R.id.textView1);
holder.txt2 = (TextView) convertView
.findViewById(R.id.textView2);
holder.txt3 = (TextView) convertView
.findViewById(R.id.textView3);
holder.txt4 = (TextView) convertView
.findViewById(R.id.textView4);
holder.txt5 = (TextView) convertView
.findViewById(R.id.textView5);
MyHScrollView headSrcrollView = (MyHScrollView) mHead
.findViewById(R.id.horizontalScrollView1);
headSrcrollView
.AddOnScrollChangedListener(new OnScrollChangedListenerImp(
scrollView1));
convertView.setTag(holder);
mHolderList.add(holder);
}
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txt1.setText(position + "" + 1);
holder.txt2.setText(position + "" + 2);
holder.txt3.setText(position + "" + 3);
holder.txt4.setText(position + "" + 4);
holder.txt5.setText(position + "" + 5);
return convertView;
}
cho tất cả tôi biết, nếu chúng ta không thể thêm xem trong xml động, nó không thể – Senthil
nhờ trả lời của bạn, tôi muốn tải dữ liệu để hiển thị như một datagrid.i đã thử giải pháp tablelayout, nhưng nó hoạt động để slow.i phải sử dụng listview nhưng bảng sqlite của tôi là thế hệ bởi objects.so bất kỳ giải pháp khác cho điều này? – Whistler