我想讓listview看起來像android.Data中的datagrid控件。所有的列都是由代碼行爲生成的,它是動態的。我的代碼片段可以成功構建,但是listview並沒有像我期望的那樣顯示。它有什麼問題?我可以在運行時在列表視圖中插入一列嗎?
@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;
}
據我所知,如果我們不能在動態XML添加視圖,它不可能 – Senthil 2013-04-09 08:37:44
感謝您的答覆,我想加載數據,顯示爲datagrid.i曾嘗試tablelayout解決方案,但它的工作slow.i必須使用listview,但我的sqlite表由object.so任何其他解決方案? – Whistler 2013-04-09 08:42:01