我正在爲當前視圖動態添加布局。即使問題是,即使我有超過兩個值的遊標只有一個視圖充氣。動態擴展視圖的問題
這意味着舊數據被覆蓋。但我想在phoneCrsr
中添加每個記錄的新視圖。
我在做什麼錯?
Cursor phoneCrsr = database.rawQuery(phoneSql, null);
while(phoneCrsr.moveToNext()){
phone_number = new ArrayList<String>();
String number = phoneCrsr.getString(phoneCrsr.getColumnIndex(MySQLiteHelper.COLUMN_PHN_NUMBER));
if(!number.isEmpty()){
phone_number.add(number);
LayoutInflater inflator = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.phone_number_textview, null);
// fill in any details dynamically here
TextView phoneTv = (TextView) view.findViewById(R.id.phone_number);
phoneTv.setText(number);
// insert into main view
LinearLayout phoneLayout = (LinearLayout) findViewById(R.id.phone_info);
phoneLayout.setVisibility(View.VISIBLE);
((ViewGroup) phoneLayout).addView(view, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
//phoneLayout.setPadding(20,0,0, 0);
//phoneLayout.setBackgroundColor(Color.WHITE);
}
Log.e("PHONE DETAIL:",phone_number.toString());
}
phoneCrsr.close();
您需要爲每條記錄創建一個視圖?爲什麼使用textview刪除視圖。使用listview和textviews它的動態 – Raghunandan
@Raghunandan:因爲我的外部視圖是'scrollview',所以它在某處閱讀我不應該在'scrollview'裏面使用'listview'。 – astuter
然後不需要scrollview coz listview滾動自己 – Raghunandan