Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. public class FindFriends extends Activity implements View.OnClickListener {
  2.  
  3. EditText handphone;
  4. Button searchbtn;
  5. String name,hp;
  6.  
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.findfriends);
  11. handphone = (EditText) findViewById(R.id.enterfn);
  12.  
  13. searchbtn = (Button) findViewById(R.id.searchfor);
  14. searchbtn.setOnClickListener(this);
  15.  
  16. ListView listview = (ListView) findViewById(R.id.listView);
  17.  
  18. String[] values = new String[]{name};
  19.  
  20. ArrayAdapter<String> codeLearnArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
  21.  
  22. listview.setAdapter(codeLearnArrayAdapter);
  23.  
  24. }
  25. @Override
  26. public void onClick(View v) {
  27. switch (v.getId()) {
  28. case R.id.searchfor:
  29. hp = handphone.getText().toString();
  30. new AttemptLogin().execute(hp);
  31. break;
  32. }
  33.  
  34. }
  35.  
  36.  
  37. class AttemptLogin extends AsyncTask<String, String, JSONObject> {
  38.  
  39. private ProgressDialog pDialog;
  40. // JSON parser class
  41. JSONParser jsonParser = new JSONParser();
  42. private static final String LOGIN_URL = "address_url";
  43.  
  44. @Override
  45. protected JSONObject doInBackground(String... args) {
  46. // TODO Auto-generated method stub
  47. // here Check for success tag
  48. try {
  49. HashMap<String, String> params = new HashMap<>();
  50. params.put("hp", args[0]);
  51. JSONObject json = jsonParser.makeHttpRequest(
  52. LOGIN_URL, "POST", params);
  53.  
  54. if (json != null) {
  55. Log.d("JSON result", json.toString());
  56.  
  57. return json;
  58. }
  59.  
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. }
  63.  
  64. return null;
  65. }
  66.  
  67. protected void onPostExecute(JSONObject json) {
  68.  
  69. if (json != null) {
  70. Toast.makeText(FindFriends.this, json.toString(),
  71. Toast.LENGTH_LONG).show();
  72.  
  73. try {
  74. name = json.getString("name");
  75. } catch (JSONException e) {
  76. e.printStackTrace();
  77. }
  78. }
  79. }
  80. }
  81.  
  82. <?xml version="1.0" encoding="utf-8"?>
  83. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  84. android:orientation="vertical" android:layout_width="match_parent"
  85. android:background="@drawable/findfriends"
  86. android:layout_height="match_parent">
  87.  
  88. <EditText
  89. android:layout_width="match_parent"
  90. android:layout_height="wrap_content"
  91. android:inputType="textPersonName"
  92. android:ems="10"
  93. android:id="@+id/enterfn"
  94. android:layout_centerVertical="true"
  95. android:layout_alignParentLeft="true"
  96. android:layout_alignParentStart="true" />
  97.  
  98. <TextView
  99. android:layout_width="wrap_content"
  100. android:layout_height="wrap_content"
  101. android:text="Enter handphone number/username to start searching"
  102. android:id="@+id/textView9"
  103. android:textSize="20dp"
  104. android:layout_above="@+id/enterfn"
  105. android:layout_alignParentLeft="true"
  106. android:layout_alignParentStart="true" />
  107.  
  108. <Button
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:text="Search"
  112. android:id="@+id/searchfor"
  113. android:layout_below="@+id/enterfn"
  114. android:layout_centerHorizontal="true" />
  115.  
  116. <ListView
  117. android:layout_width="wrap_content"
  118. android:layout_height="wrap_content"
  119. android:id="@+id/listView"
  120. android:layout_below="@+id/searchfor"
  121. android:layout_centerHorizontal="true" />
  122.  
  123. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement