Permalink
Browse files

Added callback for click and longClick of the search result listview

  • Loading branch information...
pchretien committed Aug 6, 2012
1 parent b720e9f commit 36f0c6f348abf64380f83b37838e087929911aa3
Showing with 37 additions and 6 deletions.
  1. +28 −0 src/com/basbrun/APODSearchActivity.java
  2. +9 −6 src/com/basbrun/APODSearchItem.java
@@ -6,8 +6,11 @@
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
+import android.widget.Toast;
public class APODSearchActivity extends Activity
{
@@ -26,6 +29,18 @@ public void onCreate(Bundle savedInstanceState)
searchBox = (TextView)this.findViewById(R.id.textViewSearchQuery);
listViewSearchResults = (ListView)findViewById(R.id.listViewSearchResult);
+ listViewSearchResults.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
+ return onLongListItemClick(v,pos,id);
+ }
+ });
+
+ listViewSearchResults.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
+ onListItemClick(listViewSearchResults, v,pos,id);
+ }
+ });
+
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction()))
{
@@ -41,4 +56,17 @@ public void onCreate(Bundle savedInstanceState)
listViewSearchResults.setAdapter(adapter);
}
}
+
+ protected boolean onLongListItemClick(View v, int pos, long id)
+ {
+ String message = "OnItemLongClick - " + listViewSearchResults.getItemAtPosition(pos).toString();
+ Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
+ return true;
+ }
+
+ public void onListItemClick(ListView l, View v, int position, long id) {
+ String message = "OnItemClick - " + listViewSearchResults.getItemAtPosition(position).toString();
+ Toast.makeText(this, message,
+ Toast.LENGTH_SHORT).show();
+ }
}
@@ -4,39 +4,42 @@
{
private String title;
private String date;
- private String page;
+ private String pagePath;
public APODSearchItem(String title, String date, String page)
{
super();
this.title = title;
this.date = date;
- this.page = page;
+ this.pagePath = page;
}
public String getTitle()
{
return title;
}
+
public void setTitle(String title)
{
this.title = title;
}
+
public String getDate()
{
return date;
}
+
public void setDate(String date)
{
this.date = date;
}
- public String getPage() {
- return page;
+ public String getPagePath() {
+ return pagePath;
}
- public void setPage(String page) {
- this.page = page;
+ public void setPagePath(String pagePath) {
+ this.pagePath = pagePath;
}
}

0 comments on commit 36f0c6f

Please sign in to comment.