我正在努力在列表视图中显示结果。所以这是我的申请:
第一个屏幕 - >执行和搜索的不同活动就是其中之一。用户选择搜索后,下一个屏幕有一个输入框和两个按钮。根据输入关键字,我搜索结果并希望在下一个屏幕上显示结果,但我的下一个屏幕出现,但结果不会出现。这是我的应用程序中的一些代码
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.searchcriteria);
txtSearch = (EditText)findViewById(R.id.searchstring);
btnCurrentLoc = (Button)findViewById(R.id.currentlocation);
btnCurrentLoc.setOnClickListener(new Button.OnClickListener(){
public void onClick(View view){
setContentView(R.layout.searchresults);
String keyword = txtSearch.getText().toString();
performSearch(keyword);
}
});
}
private void performSearch(String searchterm){
progressDialog = ProgressDialog.show(Search.this, "Please wait......", "Retrieving data ....",true,true);
PerformSearchTask task = new PerformSearchTask();
task.execute(searchterm);
progressDialog.setOnCancelListener(new CancelTaskOnCancelListener(task));
}
private class PerformSearchTask extends AsyncTask<String, Void, List<Event>>{
@Override
protected List<Event> doInBackground(String... arg0) {
String query = arg0[0];
return eventGetter.find(query);
}
protected void onPostExecute(final List<Event> result){
runOnUiThread(new Runnable(){
public void run() {
if(progressDialog != null){
progressDialog.dismiss();
progressDialog = null;
}
if(result != null){
Vector<String> ve = new Vector<String>();
for(Event event: result){
ve.add(event.title + "\n" + event.eventlocation + "\t" + event.eventdate);
}
String[] eventArray = new String[ve.size()];
for(int i = 0; i < ve.size(); i++){
eventArray[i] = ve.get(i);
}
ListView lv = (ListView)findViewById(R.id.list);
lv.setAdapter(new ArrayAdapter<String>(Search.this,R.layout.searchresults,eventArray));
}
}
});
}
}
Searchresults'的屏幕布局如下
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="@+id/resultsofsearch"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<RelativeLayout
android:id="@+id/relativelayout_1"
android:layout_width="320px"
android:layout_height="332px"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:id="@+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Back"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
</Button>
<Button
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</Button>
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1.0"
android:layout_below="@+id/back"
android:layout_centerHorizontal="true"
>
</ListView>
</RelativeLayout>
</ScrollView>
答案 0 :(得分:2)
我认为你应该在单独的Activity中实现每个按钮点击。它应该解决你的问题尝试这个...让我知道是否有任何困难