當前位置:首頁 » 安卓系統 » androidlistview的事件

androidlistview的事件

發布時間: 2025-08-30 18:16:15

㈠ android 的ListView中,如何判斷其內容已滾動到最頂部或者最底部

是通過ListView的OnScrollListener事件中判斷的。當listView滾動的時候就會回調OnScrollListener方法。

以下為示例代碼(完整代碼查看附件):

  1. 得到lisView實例

ListViewlistView = (ListView) findViewById(R.id.listview);


2.給ListView注冊OnScrollListener事件

listView.setOnScrollListener(new OnScrollListenerImple());


3.實現OnScrollListener 介面,處理事件。

private class OnScrollListenerImple implements OnScrollListener {

@Override

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

//如果當前列表的數量等於查詢的總數量,則不做任何操作

if(mSimpleAdapter.getCount() >= page.getRowCount()){

return;

}

if (view.getLastVisiblePosition() == (totalItemCount - 1)) { //判斷是否滑動到最底部

//已經滑動最底部了。

}

}


@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {

}

}


㈡ 請問在android的listView中怎麼動態加入radioButton和Button按鈕

在Android的ListView中動態加入RadioButton和Button按鈕,首先需要一個bean來存儲數據。這個bean里可以包含一個標志位,用來標記是要顯示RadioButton還是Button。在自定義的Adapter中的getView方法里,根據這個標志位來決定顯示哪種類型的按鈕。為了實現這一點,布局文件中需要包含兩個按鈕,一個RadioButton和一個Button,只是在初始狀態下,一個按鈕會被隱藏。具體來說,可以通過設置這些控制項的visibility屬性來實現。

當軟體的下載狀態或安裝狀態發生變化時,bean中的標志位會隨之更新。此時,只需調用Adapter的notifyDataSetChanged()方法,ListView就會重新繪制,顯示最新的按鈕。

舉個例子,假設你的bean類如下所示:

public class MyBean {
private int type; // 0表示RadioButton,1表示Button
private String text;
...
}

在Adapter的getView方法里,你可以這樣處理:

public View getView(int position, View convertView, ViewGroup parent) {
MyBean bean = getItem(position);
View view = LayoutInflater.from(context).inflate(R.layout.item_layout, null);
RadioButton radioButton = view.findViewById(R.id.radio_button);
Button button = view.findViewById(R.id.button);
if (bean.getType() == 0) {
button.setVisibility(View.GONE);
radioButton.setVisibility(View.VISIBLE);
} else {
radioButton.setVisibility(View.GONE);
button.setVisibility(View.VISIBLE);
}
return view;
}

這樣,每次數據發生變化時,ListView會自動更新顯示的內容。

㈢ Android listview的item點擊事件怎麼失效了

原因多半是由於在自己定義的Item中存在諸如ImageButton,Button,CheckBox等子控制項(也可以說是Button或者Checkable的子類控制項),此時這些子控制項會將焦點獲取到,所以常常當點擊item時變化的是子控制項,item本身的點擊沒有響應。

這時候就可以使用descendantFocusability來解決啦,API描述如下:

android:descendantFocusability

Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.

Must be one of the following constant values.

該屬性是當一個為view獲取焦點時,定義viewGroup和其子控制項兩者之間的關系。念瞎告

屬性仔明的值有三種:

  1. beforeDescendants:viewgroup會優先其子類控制項而獲取到焦點

  2. afterDescendants:viewgroup只有當其子類控制項不需要獲取焦點時才獲取焦點

  3. blocksDescendants:viewgroup會神搏覆蓋子類控制項而直接獲得焦點

通常用到的是第三種,即在Item布局的根布局加上android:descendantFocusability=」blocksDescendants」的屬性就好了

㈣ android 在一個listview中怎麼給每一項的button監聽點擊事件

首先你說的東西是一個誤區,不是每一項button而是list裡面的item,其次,將item進行點擊監聽,我寫一個點擊監聽的方法
mylistview = (ListView)findViewById(R.id.listview);
list.add("LinearLayout");
list.add("AbsoluteLayout");
list.add("TableLayout");
list.add("RelativeLayout");
list.add("FrameLayout");
ArrayAdapter<String> myArrayAdapter = new ArrayAdapter<String>
(this,android.R.layout.simple_list_item_1,list);
mylistview.setAdapter(myArrayAdapter);
mylistview.setOnItemClickListener(new OnItemClickListener(){

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
if(list.get(arg2).equals("LinearLayout"))
{
Intent intent = new Intent("com.wps.android.LINEARLAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("AbsoluteLayout"))
{
Intent intent = new Intent("com.wps.android.ABSOLUTELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("TableLayout"))
{
Intent intent = new Intent("com.wps.android.TABLELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("RelativeLayout"))
{
Intent intent = new Intent("com.wps.android.RELATIVELAYOUT");
startActivity(intent);
}
if(list.get(arg2).equals("FrameLayout"))
{
Intent intent = new Intent("com.wps.android.FRAMELAYOUT");
startActivity(intent);
}
}

});

熱點內容
python入門知乎 發布:2025-08-31 00:58:06 瀏覽:200
浪潮全快閃記憶體儲 發布:2025-08-31 00:56:35 瀏覽:740
外部存儲分析 發布:2025-08-31 00:49:36 瀏覽:251
2棟3單元會用什麼wifi密碼 發布:2025-08-31 00:47:45 瀏覽:328
線切割機床編程 發布:2025-08-31 00:42:31 瀏覽:858
資料庫行遷移 發布:2025-08-31 00:35:36 瀏覽:907
java分布式事務 發布:2025-08-30 23:53:10 瀏覽:698
安卓區怎麼看榮耀排行榜 發布:2025-08-30 23:32:12 瀏覽:871
江鈴演算法崗 發布:2025-08-30 23:28:31 瀏覽:140
ftp伺服器上傳速度 發布:2025-08-30 23:19:06 瀏覽:250