我有一个主要活动,显示从parse.com重新获得的列表(我知道parse.com正在关闭,我正在迁移到我自己的服务器上)
现在我在这个活动中有所有工作,比如onitemclick等。 但我有另一个活动,即搜索活动,搜索用户搜索的列表项是否存在于主要活动的列表中 这也可以正常工作,但是当显示搜索结果时,用户应该能够点击所需的结果并将其定向到singleitem类,就像它们处于主要活动中一样
我无法实现这一点,因为当我点击搜索结果时没有任何反应 我尝试使用onitemclicklistener实现搜索活动,就像我在主要活动中所做的那样但没有变化
我的代码
列表inimage的主要活动的aynctask及其onitem clicklistener
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new SpotsDialog(InterActivity.this, R.style.Custom);
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
codelist = new ArrayList<CodeList>();
try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"InterActivity");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
query.orderByAscending("_created_at");
query.setLimit(limit);
ob = query.find();
for (ParseObject inter : ob) {
map.setDescription((String) inter.get("subheading"));
map.setIntroduction((String) inter.get("intro"));
codelist.add(map);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (SwipeMenuListView) findViewById(R.id.inter_layoutListView);
// Pass the results into ListViewAdapter.java
adapter = new FinalAdapter(InterActivity.this,
codelist);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
listview.setOnItemClickListener(InterActivity.this);
dialog.dismiss();
}
@Override
public void onItemClick(AdapterView<?> p1, View view, int position, long p4)
{
ObjectMapper mapper = new ObjectMapper();
CodeList codes = (CodeList) adapter.getItem(position);
try{
Intent intent = new Intent(InterActivity.this, SingleItemView.class);
String jsonString = mapper.writeValueAsString(codes);
intent.putExtra("selected item", jsonString);
intent.putExtra("subheading",
(codelist.get(position).getDescription()));
intent.putExtra("intro",
(codelist.get(position).getIntroduction()));
// Start SingleItemView Class
// startActivity(intent);
startActivityForResult(intent, 1);
}catch(JsonProcessingException e){
//something went w3ong
}
}
搜索活动
public class SearchActivity extends Activity
实现OnItemClickListener {
protected EditText searchedittext;
Button searchButton;
List<ParseObject> ob;
@Override
public void onCreate(Bundle savedInstanceState )
{
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout);
searchedittext = (EditText) findViewById(R.id.search_layoutEditText);
final ListView searchedlist = (ListView) findViewById(R.id.searchlist);
searchButton = (Button) findViewById(R.id.searchlayoutbtn);
searchButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
String seaechedit = searchedittext.getText().toString();
if(seaechedit.isEmpty()){
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setMessage("PLEASE ENTER SOME SEARCH QUERY")
.setTitle("EMPTY SEARCH")
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
else{
setProgressBarIndeterminateVisibility(true);
// InterActivity is the class name in parse database where listview retrives it data from
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"InterActivity");
query.whereContains("listheading", seaechedit);
query.orderByAscending("_created_at");
query.setLimit(200);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> p1, ParseException e)
{
setProgressBarIndeterminateVisibility(false);
if(e == null){
ob = p1;
String [] searchHeadings = new String[ob.size()];
int i = 0;
// listheading is the coloumn name in parse database
for(ParseObject heading : ob){ searchHeadings[i] = (String) heading.get("listheading");
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>( SearchActivity.this, android.R.layout.simple_list_item_1, searchHeadings );
searchedlist.setAdapter(adapter);
searchedlist.setOnItemClickListener(本);
}else{
Log.e("searchactivity", e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setMessage(e.getMessage())
.setTitle("Nothing found")
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
}
});
}
@Override
public void onItemClick(AdapterView<?> p1, View view, int position, long p4)
{
ObjectMapper mapper = new ObjectMapper();
CodeList codes = (CodeList) adapter.getItem(position);
try{
Intent intent = new Intent(InterActivity.this, SingleItemView.class);
String jsonString = mapper.writeValueAsString(codes);
intent.putExtra("selected item", jsonString);
intent.putExtra("subheading",
(codelist.get(position).getDescription()));
intent.putExtra("intro",
(codelist.get(position).getIntroduction()));
// Start SingleItemView Class
// startActivity(intent);
startActivityForResult(intent, 1);
}catch(JsonProcessingException e){
//something went w3ong
}
}
答案 0 :(得分:0)
发现错误
忘记在主要活动中执行搜索活动中的RemoteDataTask