gpt4 book ai didi

Android:您的内容必须有一个 id 属性为 android.R.id.list 的 ListView

转载 作者:IT老高 更新时间:2023-10-28 22:13:01 26 4
gpt4 key购买 nike

我遇到了这个运行时错误,我真的很难找到它的根源:“您的内容必须有一个 id 属性为 android.R.id.list 的 ListView”。

这是我的代码:

public class ShowAllJobsInArea extends ListActivity{

Context context;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.show_jobs_in_area);
context=getApplicationContext();

String area=Cookie.getAreaSelected();

final ProgressBar thinger=(ProgressBar) findViewById(R.id.progressBar2);
TabHost tabHost=(TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();

TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Starting");

TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setContent(R.id.tab2);
spec2.setIndicator("# Days");

TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("Rate");


tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);

Handler handler = new Handler() {
public void handleMessage(Message message) {
switch (message.what) {
case HttpConnection.DID_START:
thinger.setVisibility(View.VISIBLE);
break;
case HttpConnection.DID_SUCCEED:
String response = (String) message.obj;
Log.i("EOH",response);

ArrayList<String> startDates=new ArrayList<String>();
ArrayList<String> ns=new ArrayList<String>();
ArrayList<String> rates=new ArrayList<String>();
HashMap<String, JSONObject> countyObjs=new HashMap<String, JSONObject>();

JSONObject object = null;
try {
object = (JSONObject) new JSONTokener(response).nextValue();

for(int i=0;i<object.length();i++){
String area="";
String endDate="";
String endTimes="";
String id="";
String startDate="";
String startTimes="";
String rate="";
String alreadyApplied="";
String n="";
JSONObject countyObj=object.getJSONObject(String.valueOf(i));
countyObjs.put(id, countyObj);

area=countyObj.getString("area");
endDate=countyObj.getString("endDate");
endTimes=countyObj.getString("endTimes");
id=countyObj.getString("id");
startDate=countyObj.getString("startDate");
startTimes=countyObj.getString("startTimes");
rate=(countyObj.getString("rates").split(","))[0];
alreadyApplied=countyObj.getString("alreadyApplied");
n=countyObj.getString("n");

startDates.add(startDate+","+id);
ns.add(n+","+id);
rates.add(rate+","+id);
}
}catch (JSONException e) {
e.printStackTrace();
}

Collections.sort(startDates);
Collections.sort(ns);
Collections.sort(rates);

String[] startDates_str = new String[startDates.size()];
startDates.toArray(startDates_str);

setListAdapter(new ArrayAdapter<String>(getApplicationContext(), R.layout.list_item, startDates_str));
//setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
ListView lv = getListView();
lv.setTextFilterEnabled(true);



thinger.setVisibility(View.INVISIBLE);

break;
case HttpConnection.DID_ERROR:
thinger.setVisibility(View.INVISIBLE);
break;
default:
break;
}
}
};

List<NameValuePair> params = new ArrayList<NameValuePair>(1);
params.add(new BasicNameValuePair("area", area));
new HttpConnection(handler).post("http://www.xlhi.com/ajax/getJobsInArea.php",params);
}
}

show_jobs_in_area.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
<TabWidget android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@android:id/tabs"></TabWidget>
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@android:id/tabcontent">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab1" android:orientation="vertical">
<ProgressBar android:id="@+id/progressBar2" android:layout_height="wrap_content" style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="25dip"></ProgressBar>
<ListView android:id="@+id/listView1" android:layout_height="wrap_content" android:layout_width="match_parent"></ListView>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab2"></LinearLayout>
<ListView android:id="@+id/listView2" android:layout_height="wrap_content" android:layout_width="match_parent">
</ListView>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab3">
<ListView android:id="@+id/listView3" android:layout_height="wrap_content" android:layout_width="match_parent"></ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

我尝试将 id 更改为 android.id="@android:id/list"无济于事 - 仍然遇到相同的错误。我在想这与我正在做的异步请求有关......我现在真的被卡住了,希望有人能提供帮助。

非常感谢,

最佳答案

如果您的布局中有多个 ListView,则不应扩展 ListActivity 而是扩展 Activity 并处理 ListViews 自己喜欢;

ListView list1 = (ListView) findViewById(R.id.myList1);
list1.setAdapter(...);

ListView list2 = (ListView) findViewById(R.id.myList2);
list2.setAdapter(...);

ListActivity 是一个速记助手类,当您在布局中只使用一个 ListView 时,它可以让您的生活更轻松。

关于Android:您的内容必须有一个 id 属性为 android.R.id.list 的 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6647831/

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