Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package com.maria_bezneayahoo.medhelper;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.AdapterView;
  8. import android.widget.ArrayAdapter;
  9. import android.widget.EditText;
  10. import android.widget.ListView;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13.  
  14. import org.w3c.dom.Text;
  15.  
  16. public class ListScreen extends Activity {
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.  
  21.         /* Set the Activity Layout */
  22.         setContentView(R.layout.activity_list_screen);
  23.  
  24.         /* Declare intent & Get information from screen calling this one */
  25.         Intent activityThatCalled = getIntent();
  26.         String type = activityThatCalled.getExtras().getString("type");
  27.         String[] results = activityThatCalled.getExtras().getStringArray("results");
  28.  
  29.         /* Set the text hint in the search box */
  30.         EditText search_hint = (EditText) findViewById(R.id.list_search);
  31.         search_hint.setHint("Search for " + type);
  32.  
  33.         /* Get the ListView and add the items*/
  34.         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_single_item, results);
  35.         ListView list = (ListView) findViewById(R.id.list_items);
  36.         list.setAdapter(adapter);
  37.  
  38.         Toast.makeText(ListScreen.this, "Everything good so far", Toast.LENGTH_LONG).show();
  39.         /* Create onClick events for each item of the list */
  40.         list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  41.             @Override
  42.             public void onItemClick(AdapterView<?> parent, View viewClicked, int position, long id) {
  43.  
  44.                 Toast.makeText(ListScreen.this, "Everything good so far", Toast.LENGTH_LONG).show();
  45.  
  46.                 /* Declare the item clicked */
  47.                 TextView textView = (TextView) viewClicked;
  48.                 String itemText = textView.getText().toString();
  49.                 textView.setText("CLICKED");
  50.  
  51.                 /* Declare the intent */
  52.                 Intent showSpecificScreen = new Intent(ListScreen.this, SpecificScreen.class);
  53.  
  54.                 /* Send information */
  55.                 showSpecificScreen.putExtra("header", itemText);
  56.  
  57.                 /* Open the List Window */
  58.                 startActivity(showSpecificScreen);
  59.             }
  60.         });
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement