I have a project which shows list of blood donors using place search, i want to insert a call button in that list view for each user, i have no idea how to add it, Can you please help me with this? Screenshot 1: Screenshot 2:
Each detail of the blood donor like name , blood group and phone are stored in each field in the server. "bld_phn" is the id of text view that shows phone number."phone" is the array string
code:
public class blood extends Activity {
AsyncHttpClient client;
JSONArray jarray;
JSONObject jobject;
RequestParams params;
ListView lv;
EditText enter;
Button done;
Button call;
ArrayList<String> place;
ArrayList<String>incharge;
ArrayList<String>email;
ArrayList<String>phone;
ArrayList<String>reg;
ArrayList<String>Bld;
String temp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.blood);
//prof=(EditText)findViewById(R.id.userProfile);
client = new AsyncHttpClient();
params = new RequestParams();
// submit=(Button)findViewById(R.id.submit);
lv = (ListView) findViewById(R.id.List_all_blood);
enter=(EditText)findViewById(R.id.enter_bld);
done=(Button)findViewById(R.id.enter_blood);
place = new ArrayList<String>();
incharge = new ArrayList<String>();
email = new ArrayList<String>();
phone = new ArrayList<String>();
reg = new ArrayList<String>();
Bld = new ArrayList<String>();
// final RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl2);
// findViewById(R.id.rl1).setOnClickListener(new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(rl.getWindowToken(), 0);
//
// }
// });
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
place.clear();
incharge.clear();
email.clear();
phone.clear();
reg.clear();
String pl=enter.getText().toString();
params.put("place",pl);
client.get("http://srishti-systems.info/projects/accident/bloodsearch.php?", params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String content) {
// TODO Auto-generated method stub
super.onSuccess(content);
System.out.println(content + "jjjjj");
try {
jobject = new JSONObject(content);
Log.e(content, "hgsfdh");
String s = jobject.optString("Result");
Log.e(content,"dsfds");
if(s.equals("success")){
// SharedPreferences pref=getApplicationContext().getSharedPreferences("pref",MODE_PRIVATE);
// temp=pref.getString("user","");
// String a = jobject.optString("PoliceDetails");
jarray =jobject.getJSONArray("BloodDoner");
for (int i = 0; i < jarray.length(); i++) {
JSONObject obj = jarray.getJSONObject(i);
String FN = obj.getString("firstname");
place.add("First Name :" + FN);
String LN = obj.getString("lastname");
incharge.add("Second Name :" + LN);
String mail = obj.getString("email");
email.add("Email :" + mail);
String ph = obj.getString("phone");
phone.add("Phone :" + ph);
String bd = obj.getString("bloodgrp");
Bld.add("BLood Group :" + bd);
}
}
else
Toast.makeText(getApplicationContext(),"No Donors Found",Toast.LENGTH_LONG).show();
adapter adpt = new adapter();
lv.setAdapter(adpt);
} catch (Exception e) {
}
}
});
}
});
}
public void hideKeyboard(View view) {
InputMethodManager imm =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
class adapter extends BaseAdapter {
LayoutInflater Inflater;
@Override
public int getCount() {
// TODO Auto-generated method stub
return place.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Inflater=(LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=Inflater.inflate(R.layout.blood_lst,null);
Viewholder holder=new adapter.Viewholder();
holder.pl=(TextView)convertView.findViewById(R.id.bld_name);
holder.pl.setText(place.get(position));
holder.in=(TextView)convertView.findViewById(R.id.bld_nm);
holder.in.setText(incharge.get(position));
holder.em=(TextView)convertView.findViewById(R.id.bld_em);
holder.em.setText(email.get(position));
holder.ph=(TextView)convertView.findViewById(R.id.bld_phn);
holder.ph.setText(phone.get(position));
holder.ph=(TextView)convertView.findViewById(R.id.bld_grp);
holder.ph.setText(Bld.get(position));
return convertView;
}
class Viewholder{
TextView pl;
TextView in;
TextView em;
TextView ph;
}
}
}
xml of the page :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rl2"
android:background="#9e9e9e">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="@+id/List_all_blood"
android:layout_below="@+id/enter_bld"
/>
<EditText
android:hint="enter place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/enter_bld"
android:layout_weight="1"
android:layout_marginTop="49dp"
android:textColor="#000000"
android:textStyle="italic"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/enter_policebutton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:text="done"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:textColor="#FFFFFF"
android:background="#3F51B5"
android:layout_marginRight="34dp"
android:layout_marginEnd="34dp"
android:id="@+id/enter_blood"
style="@style/Widget.AppCompat.Button"
android:layout_alignBaseline="@+id/enter_bld"
android:layout_alignBottom="@+id/enter_bld"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/enter_blood"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="11dp"
android:text="Blood Doners" />
</RelativeLayout>
xml of the list :
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9e9e9e">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="25dp"
android:textSize="15dp"
android:layout_marginLeft="30dp"
android:id="@+id/bld_name" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="30dp"
android:textSize="15dp"
android:textColor="#000000"
android:id="@+id/bld_nm"
android:layout_below="@+id/bld_name" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="15dp"
android:textSize="15dp"
android:layout_marginLeft="30dp"
android:id="@+id/bld_em" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="15dp"
android:textSize="15dp"
android:layout_marginLeft="30dp"
android:id="@+id/bld_phn" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_marginTop="15dp"
android:textSize="15dp"
android:layout_marginLeft="30dp"
android:id="@+id/bld_grp" />
</TableLayout>