當前位置:首頁 » 安卓系統 » android顯示listview中

android顯示listview中

發布時間: 2022-06-03 18:20:37

⑴ android 怎麼把存入資料庫的信息顯示在ListView中

訪問並查詢資料庫將數據取出 ,然後用adapter綁定到listview就行了

⑵ android中怎麼把數組的內容在ListView中顯示

數組的內容顯示在list上需要三大步:

1.ListVeiw 用來展示列表的View。

2.適配器Adapter 用來把數據映射到ListView上。

3.數據 具體的將被映射的字元串,圖片,或者基本組件。
根據列表的適配器類型,列表分為三種,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter

如果僅僅將數組的內容顯示到ListView 上ArrayAdapter就夠了
public classTest extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] sw = new String[10];
for (int i = 0; i < 10; i++) {
sw[i] = "List_" + i;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sw);//使用系統已經實現好的xml文件simple_list_item_1
setListAdapter(adapter);
}
}
//這樣就容易的用系統已經實現的layout很快速的實現了listview載入數組sw,這樣實現只能簡單的將數組中的數據列在每一行上,同一行上不能添加其他東西,比如:圖片/按鍵等
如果在同一行上進行不同的操作,可以用SimpleAdapter
如果在同一行上添加對象之類的,比如新浪微薄上每一條微薄、人人上每一條分享之類的,就要自己寫類繼承與BaseAdapter重寫其中的getView方法

祝你好運~~

⑶ android如何將從資料庫讀取的數據顯示在listview中

final SimpleAdapter adapter = new SimpleAdapter(this, getData(),
R.layout.mainlayout, new String[] { "text", "time", "image" },
new int[] { R.id.PL_TextView01, R.id.PL_TextView02,
R.id.PL_ImageView01 });
lv.setAdapter(adapter);

private List<Map<String, Object>> getData() {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();

Cursor cur = DR.query("DB", new String[] { "text", "time" }, null,
null, null, null, "time desc");
while (cur.moveToNext()) {
for (int i = 0; i < cur.getCount(); i++) {
cur.moveToPosition(i);
String text = cur.getString(0);
String time = cur.getString(1);

map = new HashMap<String, Object>();

map.put("text", text);
map.put("time", time);
map.put("image", R.drawable.ic_menu_close_clear_cancel);
list.add(map);
}
}

return list;
}

我是使用SimpleAdapter 作為listview的適配器 通過數據的query方法 將數據放入listview

⑷ android 中listView顯示的問題

這個不知道

⑸ Android 開發裡面,如何點擊Button將EditText裡面的內容發送出去並顯示在ListView當中

樓主您好,很高興為您解答,如果您要做以上操作的話,首先您要得到以上幾個控制項的對象,得到對象後為Button設置監聽器,代碼:
button.setOnClickListener(new OnClickLIstener()
{
String str = editText.getText();//得到EditText裡面的內容
//樓主要想顯示在ListView裡面的話只有一個簡單的ArrayAdapter就行了
//但是ArrayAdapter最後一個構造參數是接受一個String的數組,所以要先把上面的str改變成數組
String[] arr = {str}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this , android.R.layout.simple_list_item_2 ,arr)
listView.setAdapter(adapter);
//搞定了
});
代碼就是這么多,希望能幫到您

⑹ android手機應用開發中如何用listview顯示一個表呢

  1. 展示的效果可能類似於下圖:

    <LinearLayoutxmlns="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
    android:id="@+id/name_tv"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>
    <TextView
    android:id="@+id/price_tv"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>

    </LinearLayout>

⑺ Android 將頁面加到ListView中

不用listview, 直接用一個 ScrollView包起來即可以上下滑動了, listView是用來顯示我條相同的數據用的, 用ScrollView這樣的控制項即可.

⑻ android中怎麼讓listview的內容全部顯示出來

注意,如果listitem裡面有textview的話,就當一行處理進行截取數字。
public static void (ListView listView) {
// 獲取ListView對應的Adapter WeiboContentAdapter listAdapter = (WeiboContentAdapter) listView.getAdapter(); if (listAdapter == null) { return; } Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setTextAlign(Align.LEFT); LinearLayout listItem; TextView tvContent; int totalHeight = 0; int lineCount = 0; for (int i = 0, len = listAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回數據項的數目 listItem = (LinearLayout)listAdapter.getView(i, null, listView); tvContent = (TextView) listItem.findViewById(R.id.tv_weibo_detail_content); lineCount = getLineCount(mPaint, ((SpannedString) tvContent.getText()).toString()); tvContent.measure(0, 0); // 計運算元項View 的寬高 totalHeight += tvContent.getMeasuredHeight()*lineCount + 60; // 統計所有子項的總高度 } ViewGroup.LayoutParams params = listView.getLayoutParams(); params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)) ; // listView.getDividerHeight()獲取子項間分隔符佔用的高度 // params.height最後得到整個ListView完整顯示需要的高度 listView.setLayoutParams(params); }
private static int getLineCount(Paint mPaint, String content) { int index; int count = 0; while(content.length() > 0){ index = mPaint.breakText(content, true, ResolutionUtil.getWPx()/2, null); content = content.substring(index); count++; } return count; }
/** * 動態改變listView的高度 * @param pull */ private void setPullLvHeight(ListView pull){ int totalHeight = 0; for (int i = 0, len = adapter.getCount(); i < len; i++) { //listAdapter.getCount()返回數據項的數目 View listItem = adapter.getView(i, null, pull); listItem.measure(0, 0); //計運算元項View 的寬高 totalHeight += listItem.getMeasuredHeight(); //統計所有子項的總高度 } ViewGroup.LayoutParams params = pull.getLayoutParams(); params.height = totalHeight + (pull.getDividerHeight() * (pull.getCount() - 1)); pull.setLayoutParams(params); }

熱點內容
小米自動上傳 發布:2025-05-20 05:06:06 瀏覽:623
王者榮耀引流腳本 發布:2025-05-20 05:06:03 瀏覽:484
無人深空pc需要什麼配置 發布:2025-05-20 04:55:17 瀏覽:614
可編程式恆溫恆濕試驗箱 發布:2025-05-20 04:54:34 瀏覽:367
visibilityandroid 發布:2025-05-20 04:54:26 瀏覽:699
android磁場感測器 發布:2025-05-20 04:50:46 瀏覽:828
python經典編程題 發布:2025-05-20 04:42:33 瀏覽:782
xp電腦訪問win7 發布:2025-05-20 04:41:59 瀏覽:617
金融的配置是什麼 發布:2025-05-20 04:41:07 瀏覽:466
解壓擠耳朵 發布:2025-05-20 04:37:02 瀏覽:887