自定義listView出錯
自定義一個如下listview時
package com.example.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.text.Layout; import android.util.AttributeSet; import android.widget.ListView; public class SpinListView extends ListView{ public SpinListView(Context context) { super(context); // TODO Auto-generated constructor stub } @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); Paint paint = new Paint(); final android.view.ViewGroup.LayoutParams layout = getLayoutParams(); final int left = getListPaddingLeft(); final int top = getListPaddingTop(); paint.setColor(android.graphics.Color.BLACK); canvas.drawLine(left + layout.width, top, left + layout.width + 4, top + 4, paint); canvas.drawLine(left + layout.width + 4, top + 4, left + layout.width, top + 8 , paint); } }
出現如下錯誤:
D/dalvikvm( 9962): Debugger has detached; object registry had 1 entries
D/AndroidRuntime( 9972): Shutting down VM
W/dalvikvm( 9972): threadid=1: thread exiting with uncaught exception (group=0x41124930)
E/AndroidRuntime( 9972): FATAL EXCEPTION: main
E/AndroidRuntime( 9972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class com.example.test.SpinListView
E/AndroidRuntime( 9972): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
E/AndroidRuntime( 9972): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
E/AndroidRuntime( 9972): at android.app.ActivityThread.access$600(ActivityThread.java:141)
E/AndroidRuntime( 9972): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
E/AndroidRuntime( 9972): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 9972): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 9972): at android.app.ActivityThread.main(ActivityThread.java:5041)
E/AndroidRuntime( 9972): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9972): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 9972): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 9972): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 9972): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 9972): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.example.test.SpinListView
E/AndroidRuntime( 9972): at android.view.LayoutInflater.createView(LayoutInflater.java:596)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime( 9972): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
E/AndroidRuntime( 9972): at android.app.Activity.setContentView(Activity.java:1881)
E/AndroidRuntime( 9972): at com.example.test.MainActivity.onCreate(MainActivity.java:12)
E/AndroidRuntime( 9972): at android.app.Activity.performCreate(Activity.java:5104)
E/AndroidRuntime( 9972): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
E/AndroidRuntime( 9972): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
E/AndroidRuntime( 9972): ... 11 more
E/AndroidRuntime( 9972): Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
E/AndroidRuntime( 9972): at java.lang.Class.getConstructorOrMethod(Class.java:460)
E/AndroidRuntime( 9972): at java.lang.Class.getConstructor(Class.java:431)
E/AndroidRuntime( 9972): at android.view.LayoutInflater.createView(LayoutInflater.java:561)
E/AndroidRuntime( 9972): ... 22 more
W/ActivityManager( 359): Force finishing activity com.example.test/.MainActivity
I/Process ( 9972): Sending signal. PID: 9972 SIG: 9
I/ActivityManager( 359): Process com.example.test (pid 9972) has died.
W/InputMethodManagerService( 359): Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected]
這是由於有一個建構函式沒有定義,新增如下建構函式:
public SpinListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
相關推薦
自定義listView出錯
自定義一個如下listview時 package com.example.test; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint
Android UI 自定義ListView 實現下拉重新整理 載入更多
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
【封裝】Android自定義ListView
ListView中的Item介面 <!-- view_fileitem --> <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.an
自定義ListView重新整理,上拉載入
XListView public class XListView extends ListView implements OnScrollListener { private float mLastY = -1; // save event y private Scroller
Android 自定義Listview 與巢狀ScrollView
本文講實現一個自定義列表的Android程式,程式將實現一個使用自定義的介面卡(Adapter)繫結資料,通過ontextView.setTag繫結資料有按鈕的ListView。 系統顯示列表(ListView)時,首先會例項化一個介面卡,本文將例項化一個自定義的介面卡。實現自
自定義ListView下拉重新整理上拉載入更多功能
本篇的自定義listview包含下拉重新整理和上拉載入更多都是自定義。如果你想把重新整理的圖片做的更炫只需要更換下圖片加上適當的動畫就OK咯!由於沒有合適的圖片就用了個粗糙的。不好看請見諒。 //部分程式碼(都做了註釋): /** * @author: ZQF_
自定義listView及其adapter動態重新整理
轉自:http://www.2cto.com/kf/201203/122878.html 本文主要探討自定義的adapter及其notifyDataSetChanged()方法的使用(無listView的監聽部分): 先上圖看下效果:(整個操作過程中,當前Activity未被p
android 自定義ListView顯示微信聊天好友列表
我們使用listView實現顯示微信好友列表,如下圖所示 這是MainActivity的程式碼如下: <span style="font-size:18px;">package com.listviewdodo; import java.util.Arr
我的第一篇部落格--ScrollView中巢狀自定義ListView顯示不全的解決方案
之前在開發過程中遇到過ScrollView巢狀ListView的開發需求,如果listview的item高度固定的話,可以通過繼承listview進行重寫onMeasure()方法可以完美解決滑動衝突等問題,程式碼如下: public class ChildListVie
自定義ListView實現下拉重新整理和上拉載入
實現ListView的下拉重新整理和上拉載入,需要先新增headerView和footerView,通過在拖動的過程中,控制頭尾佈局的paddingTop實現。先把paddingTop設為負值,來隱藏header,在下拉的過程中,不斷改變headerView的p
自定義ListView中的分割線
ListView中每個Item項之間都有分割線,設定android:footerDividersEnabled表示是否顯示分割線,此屬性預設為true。 1.不顯示分割線只要在ListView控制元件中新增android:footerDividersEnabled="fal
android 可拖拽自定義listview;
在開發systemUi過程中,要求像小米的開關排序進行拖拽新增,對控制中心的每個按鈕新增更新;經過不停的探索,最終實現出結果; 下面我們來看實現; 我們先看values下的xml的實現: colors.xml <?xml version="1.
再也不用擔心下拉重新整理,上拉載入啦!-自定義ListView對上拉重新整理,上拉載入的詳解
前言: 看過許多下拉重新整理的例子,好多大牛們的程式碼寫的很完美,讓人羨慕嫉妒恨~~~,可是,對於下拉重新整理時的手勢操作卻沒有給出詳細的解釋,當一堆堆邏輯程式碼出來的時候,對於我們這些菜鳥來說,理解起來真是讓人腦子都大了。為了解放大腦(懶得自己進行全面分析),
Android 自定義Listview 如何繫結Sqlite資料庫資料
首先我們需要有個載入的檔案,這個佈局檔案裡面的bills.xml,這個佈局裡面有個Listview控制元件。 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns
根據listview的條目長度撐滿pop的自定義ListView
public class ListViewAdaptWidth extends ListView { public ListViewAdaptWidth(Context context) { super(context); } public
自定義ListView【通用】介面卡並實現監聽控制元件!
ListView :在Android應用開發過程中屬於最常用的系統元件之一,當然可能童鞋們問為什麼會突然遊戲開發中講這個,呵呵,其實在遊戲開發中,也會常常使用到系統元件,比如遊戲排行榜,簡單的遊戲關卡選擇等等,都可以來使用ListView來實現; 當然關於ListView我想大家都會使用了,那麼這篇文章
23—自定義ListView【通用】介面卡並實現監聽控制元件
ListView :在Android應用開發過程中屬於最常用的系統元件之一,當然可能童鞋們問為什麼會突然遊戲開發中講這個,呵呵,其實在遊戲開發中,也會常常使用到系統元件,比如遊戲排行榜,簡單的遊戲關卡選擇等等,都可以來使用ListView來實現;當然關於ListView我想大
解決自定義ListView中滑動事件和點選的setOnItemClickListener事件衝突的問題
解決自定義ListView滑動事件和點選事件衝突的問題 一、問題描述 自定義的ListView加入下拉重新整理和上拉載入更多後會出現滑動時觸發了點選單個條目的setOnItemClickListene
android 自定義ListView實現下拉重新整理、分頁載入、點選事件——自定義控制元件學習(七)
package com.example.administrator.customerpulldownrefreshandpageload; import android.content.Context; import android.os.Handler; import android.os.Message
自定義ListView子專案佈局
之前學習的ListView都是採用android系統自帶的子專案佈局,比如android.R.layout.simple_list_item_1(單行文字),以及android.R.layout.simple_list_item_2(雙行文字) 但是實際軟體開發中我們更希望