gpt4 book ai didi

机器人 : customer List Adatper + ArrayList

转载 作者:行者123 更新时间:2023-11-30 04:52:42 25 4
gpt4 key购买 nike

团队,

你能帮我调试这个问题吗?

ActivityAdapter activityAdapter = new ActivityAdapter(this,activityList); Log.d("列表", "列表显示 - 1");

    setListAdapter( activityAdapter );
Log.d("List", "list done");

在setListAdapter的时候抛出异常,

05-01 16:59:15.996: WARN/dalvikvm(251): threadid=3: 线程退出并出现未捕获的异常 (group=0x4001b188)05-01 16:59:15.996:错误/AndroidRuntime(251):未捕获的处理程序:由于未捕获的异常,线程主要退出05-01 16:59:16.204: ERROR/AndroidRuntime(251): java.lang.RuntimeException: 无法启动 Activity ComponentInfo{com.antennasoftware.xml/com.antennasoftware.xml.XMLParsing}: java.lang.RuntimeException: 你的content 必须有一个 ListView,它的 id 属性是 'android.R.id.list'05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2454)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2470)05-01 16:59:16.204: 错误/AndroidRuntime(251): 在 android.app.ActivityThread.access$2200(ActivityThread.java:119)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.ActivityThread$H.handleMessage (ActivityThread.java:1821)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.os.Handler.dispatchMessage (Handler.java:99)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.os.Looper.loop (Looper.java:123)05-01 16:59:16.204: 错误/AndroidRuntime(251): 在 android.app.ActivityThread.main(ActivityThread.java:4310)05-01 16:59:16.204:错误/AndroidRuntime(251):在 java.lang.reflect.Method.invokeNative( native 方法)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 java.lang.reflect.Method.invoke (Method.java:521)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:860)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 dalvik.system.NativeStart.main (Native Method)05-01 16:59:16.204: ERROR/AndroidRuntime(251): Caused by: java.lang.RuntimeException: 你的内容必须有一个 ListView,它的 id 属性是 'android.R.id.list'05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.ListActivity.onContentChanged (ListActivity.java:236)05-01 16:59:16.204:错误/AndroidRuntime(251):在 com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)05-01 16:59:16.204:错误/AndroidRuntime(251):在 android.app.Activity.setContentView(Activity.java:1622)05-01 16:59:16.204:错误/AndroidRuntime(251):在 com.antennasoftware.xml.XMLParsing.onCreate(XMLParsing.java:36)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047)05-01 16:59:16.204: 错误/AndroidRuntime (251): 在 android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2417)05-01 16:59:16.204: 错误/AndroidRuntime(251): ... 11 更多

类 ActivityList 扩展了 LinearLayout {

public ActivityList(Context context, ActivityBean activityBean) {
super(context);

this.setOrientation(HORIZONTAL);
ListView listView = new ListView(context);
LinearLayout.LayoutParams idParams =
new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
//cityParams.setMargins(10, 10, 10, 10);

TextView idColumn = new TextView( context );
idColumn.setText( activityBean.getActivityId() );
idColumn.setTextSize(14f);
idColumn.setTextColor(Color.WHITE);
listView.addView( idColumn, idParams);

LinearLayout.LayoutParams accountNameParams =
new LinearLayout.LayoutParams(20, LayoutParams.WRAP_CONTENT);


TextView accountNameView = new TextView(context);
accountNameView.setText( activityBean.getAccountName() );
accountNameView.setTextSize( 14f );
accountNameView.setTextColor(Color.WHITE);
listView.addView( accountNameView, accountNameParams);

LinearLayout.LayoutParams typeParams =
new LinearLayout.LayoutParams(25, LayoutParams.WRAP_CONTENT);

//ImageView skyControl = new ImageView( context );
TextView typeView = new TextView(context);
typeView .setText( activityBean.getAccountName() );
typeView.setTextSize( 14f );
typeView .setTextColor(Color.WHITE);
listView.addView( typeView, typeParams );
addView(listView);
}

公共(public)类 ActivityAdapter 扩展 BaseAdapter{

public ActivityAdapter(Context context, List activityList) {
this.context = context;
this.activityList = activityList;
}

private Context context;
private List activityList;

@Override
public int getCount() {
// TODO Auto-generated method stub
return activityList.size();
}

@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ActivityBean activity = (ActivityBean) activityList.get(position);
return new ActivityList(this.context, activity );

}

提前致谢

最佳答案

您正在使用 ListActivity,这要求您在内容 XML 中有一个 ListView,其 id 为“@id:android/list”

参见 documentation for ListActivity了解更多详情。

关于机器人 : customer List Adatper + ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2750107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com