Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FindFriends extends Activity implements View.OnClickListener {
- EditText handphone;
- Button searchbtn;
- String name,hp;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.findfriends);
- handphone = (EditText) findViewById(R.id.enterfn);
- searchbtn = (Button) findViewById(R.id.searchfor);
- searchbtn.setOnClickListener(this);
- ListView listview = (ListView) findViewById(R.id.listView);
- String[] values = new String[]{name};
- ArrayAdapter<String> codeLearnArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
- listview.setAdapter(codeLearnArrayAdapter);
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- case R.id.searchfor:
- hp = handphone.getText().toString();
- new AttemptLogin().execute(hp);
- break;
- }
- }
- class AttemptLogin extends AsyncTask<String, String, JSONObject> {
- private ProgressDialog pDialog;
- // JSON parser class
- JSONParser jsonParser = new JSONParser();
- private static final String LOGIN_URL = "address_url";
- @Override
- protected JSONObject doInBackground(String... args) {
- // TODO Auto-generated method stub
- // here Check for success tag
- try {
- HashMap<String, String> params = new HashMap<>();
- params.put("hp", args[0]);
- JSONObject json = jsonParser.makeHttpRequest(
- LOGIN_URL, "POST", params);
- if (json != null) {
- Log.d("JSON result", json.toString());
- return json;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- protected void onPostExecute(JSONObject json) {
- if (json != null) {
- Toast.makeText(FindFriends.this, json.toString(),
- Toast.LENGTH_LONG).show();
- try {
- name = json.getString("name");
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="match_parent"
- android:background="@drawable/findfriends"
- android:layout_height="match_parent">
- <EditText
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="textPersonName"
- android:ems="10"
- android:id="@+id/enterfn"
- android:layout_centerVertical="true"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Enter handphone number/username to start searching"
- android:id="@+id/textView9"
- android:textSize="20dp"
- android:layout_above="@+id/enterfn"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Search"
- android:id="@+id/searchfor"
- android:layout_below="@+id/enterfn"
- android:layout_centerHorizontal="true" />
- <ListView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/listView"
- android:layout_below="@+id/searchfor"
- android:layout_centerHorizontal="true" />
- </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement